Displaying 20 results from an estimated 85 matches for "accepts_nested_attributes_for".
2009 Jun 24
1
accepts_nested_attributes_for :reject_if issue
I have the following models:
class Order < ActiveRecord::Base
belongs_to :billing_address
belongs_to :shipping_address
accepts_nested_attributes_for :billing_address
accepts_nested_attributes_for :shipping_address, :reject_if => proc {
|attributes| attributes[''has_shipping_address''] != ''1'' }
def after_initialize
self.build_billing_address unless billing_address
self.build_shipping_address unle...
2013 Mar 14
0
[Rails 3.2] accepts_nested_attributes_for and time_select
Hi, I am upgrading a Rails application from Rails 3.1.11 to 3.2.12, but
have a problem with ` accepts_nested_attributes_for` in conjunction with
multipart attributes.
The app is used to manage oral exams, so there is a model `Exam`, which has
many `Examdate`s. When creating an exam, I can also create the examdates,
consisting of a date, a start time and an end time. While the date field is
edited using a text field...
2010 Feb 25
1
accepts_nested_attributes_for vs. multiple controllers on one page
...er the results from show, create, edit and delete
actions for several different models (one controller per model) on one
page.
While these several models are conceptually related, they do not need
to be associated with each other. So, I''d rather not impose
associations on them just to use accepts_nested_attributes_for to
facilitate their presentation in a common form.
All I want is a page that presents the several models, links to their
associated actions, and, finally, the results of these actions.
As a beginner, I''m having a hard-time fitting this requirement into
the RESTful approach, where, as I u...
2010 Feb 06
1
accepts_nested_attributes_for with has_many => :through
I have two models, links and tags, associated through a 3rd model,
link_tags. I added the following to my link model,
has_many :tags, :through => :link_tags
has_many :link_tags
accepts_nested_attributes_for :tags, :allow_destroy => :false,
:reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
and put this in a partial called by the new and edit forms for links,
<%= f.error_messages %>
<p>
<%= f.label :uri %><br />
<%= f.text_field :uri %>...
2013 Nov 10
3
accepts_nested_attributes_for how, example
...ot;Pictures", "Movies", etc), text box for title and text-area for content.
I followed many tutorials and documentation like:
http://railscasts.com/episodes/196-nested-model-form-part-1 and
http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for
but can''t get it how to work.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCG...
2009 Jul 28
0
'double' nest form fields with accepts_nested_attributes_for
Hi
Is it possible to ''double'' nest form fields with
accepts_nested_attributes_for?
Something like:
[code=ruby]<% form_for parent do |parent_form| %>
<% parent_form.fields_for parent_children do |parent_children_fields|
%>
...
<% parent_children_fields.fields_for parent_child_activities do
| parent_child_activities_fields| %>
...[/c...
2011 Jul 16
0
nested_form gem don't work for accepts_nested_attributes_for :limit
Hello, I have the next:
class Post < ActiveRecord::Base
has_many :image, :dependent => :destroy
accepts_nested_attributes_for :image, :allow_destroy => true, :limit
=> 4
end
class Image < ActiveRecord::Base
belongs_to :Post
... paperclip settings ...
end
And the form view for the post is:
<%= nested_form_for @post, :html => { :multipart => true } do |f| %>
<%= f.fields_for :images do |i| %...
2011 Sep 27
0
accepts_nested_attributes_for is not working for uniqueness
class User < ActiveRecord::Base
accepts_nested_attributes_for :emails, :allow_destroy => true,
:reject_if => proc { |attributes| attributes[''address''].blank? }
end
class Email < ActiveRecord::Base
belongs_to :user
validates_presence_of :address
validates_email_format_of :address
validates_uniqueness_of :address, :s...
2012 Aug 25
0
accepts_nested_attributes_for and fields_for not working!
...nu = Menu.find(params[:id])
@menu.dinners.build
@menu.lunches.build
@menu.brunches.build
end
Menu Model:
class Menu < ActiveRecord::Base
has_many :brunches, :dependent => :destroy
has_many :lunches, :dependent => :destroy
has_many :dinners, :dependent => :destroy
accepts_nested_attributes_for :lunches, :dinners, :brunches
end
Brunch, lunch, dinner models:
class Lunch < ActiveRecord::Base
attr_accessible :menu_id, :lunch_menu
belongs_to :menu
mount_uploader :lunch_menu, ImageUploader
end
Menu Form:
<%= form_for @menu, :html => {:multipart => true} do |f| %>
&l...
2010 Nov 28
6
has_one accepts_nested_attributes_for fields_for NOT WORKING HELP
MODEL
class User < ActiveRecord::Base
has_one :address, :dependent => :destroy
accepts_nested_attributes_for :address
end
CONTROL
def new
@user = User.new
@user.build_address # Adicionei
...
VIEW partial _form
....
<% f.fields_for :address do |b| %> # Adicionei
<%= b.text_field :city_manual %> # Adicionei
<% end %> # Adicione...
2009 Jul 08
0
accepts_nested_attributes_for and has_one
Hi all, I''m seeing some unexpected behaviour in a nested model and I''m
not sure if it''s a bug or if I''m doing something wrong. When
assigning nested attributes, the associated object gets replaced with
a new record.
Example code:
class Car < ActiveRecord::Base
belongs_to :driver
end
class Car < ActiveRecord::Base
belongs_to :driver
end
2010 Mar 09
0
undefined method `accepts_nested_attributes_for' for #<Class:
Sorry for the newb question,
but it is: going through first steps I fond this exception.
Have no idea, my rails version is 2.3.5
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
2011 Apr 07
0
accepts_nested_attributes_for, validations, :inverse_of option on associations, and IdentityMap
This feels more like a question to ask the core list, forgive me if I trespass.
I''ve been trying to help one of my cow orkers get through a sticky
problem. He''s got a fairly complex nested form to update a model and
its children. He''s started adding some validations, and we''ve
encountered a number of issues:
First he had a validation on one of the child
2010 Oct 07
1
Question on polymorphic association
I have 3 models . Doctor, Patient and User
with following associations
class Doctor < ActiveRecord::Base
has_many :patients, :dependent => :destroy
has_one :user, :as => :userable
accepts_nested_attributes_for :user
end
class Patient < ActiveRecord::Base
belongs_to :doctor
has_one :user, :as => :userable
accepts_nested_attributes_for :user
end
class User < ActiveRecord::Base
belongs_to :userable, :polymorphic => true
end
I have a nested form for doctor and user as
OUTER FORM for :docto...
2013 Mar 30
1
How to use group in nested associations
..._entries).select("timesheets.*,
sum(time_entries.worktime) as total").group("timesheets.start_date")
The models have the following relations:
Timesheet < AR
has_many :activities, dependent: :destroy, inverse_of: :timesheet
has_many :time_entries, through: :activities
accepts_nested_attributes_for :activities, allow_destroy: true
end
class Activity < AR
belongs_to :timesheet, inverse_of: :activities
belongs_to :task
has_many :time_entries, order: :workdate, dependent: :destroy,
inverse_of: :activity
accepts_nested_attributes_for :time_entries, allow_destroy: true,
reject_if: pr...
2009 Oct 15
4
Getting the object in fields_for
I''m using the fields_for helper with accepts_nested_attributes_for
The System model has_many children.
If I do this in my haml template:
-form_for @system do |s|
=s.text_field :name
-s.fields_for :children do |child_fields|
=child_fields.text_field :name
all is fine. The fields_for iterates over all children and puts the
correct data in the...
2010 Mar 01
3
has_many models in a form
Hi, guys.
There are four models in the program, A has_many B through C, B has_many
A through C, A has_many D, D belongs_to A. I have a form to create A.
Inspired by Ryan Bates'' railscasts I was able to create A and D in the
same form, and link A to B(created beforehand) through C in the same
form as well. Is it possible to create A and B in the same form?
Thanks in advance.
--
Posted
2013 Mar 25
1
validates presence of foreign key fails in nested form
I''m using accepts_nested_attributes as follows:
class Timesheet < ActiveRecord::Base
attr_accessible :status, :user_id, :start_date, :end_date,
:activities_attributes
has_many :activities, dependent: :destroy
has_many :time_entries, through: :activities
accepts_nested_attributes_for :activities, allow_destroy: true
end
class Activity < ActiveRecord::Base
attr_accessible :task_id, :timesheet_id, :time_entries_attributes
validates :task_id, presence: true, uniqueness: { scope: ''timesheet_id''}
belongs_to :timesheet
belongs_to :task
has_many :time_e...
2012 Aug 13
10
Question about PATCH method, accepts_nested_attributes_for, and updates to association lists (has_many, HABTM)
...have a question/concern, and forgive me if I''m misunderstanding it.
So, if the request parameter _method is set to "patch", the update is
processed as a patch.
But, let''s say you have a model called Airplane and Airplane has a
collection of FlightCrewMembers which it accepts_nested_attributes_for. You
get the Airplane resource via a RESTful call to Rails that contains the
FlightCrewMembers list. Then something needs to make a PATCH to this
resource and change both an attribute called autopilot_engaged on the
Airplane while only changing the active_pilot flag of one of the
FlightCrewMem...
2013 Dec 10
2
form_tag + fields_for Rails 4
...lt; ApplicationController
> def new
> @campus = Campus.new
> end
>
> def create
> @campus = Campus.new(campus_params)
> @campus.church_id = session[:church_id]
> # i''m just trying this way, because it''s not creating automatic
> (accepts_nested_attributes_for)
> * @campus.addresses.new(params[:addresses]) # the error line*
>
> if @campus.save!
> ...
> else
> ...
> end
>
> private
>
> # Never trust parameters from the scary internet, only allow the white
> list through.
&g...