Ruby on Rails Friday, May 22, 2015

Thanks, but I think that I figured it out

In parent AR,

attr_accessible :addresses_attributes
has_many :addresses  ### Pretty sure should be plural for has_many, and singular for has_one
accepts_nested_attributes_for :addresses

Then in the view I have (abbreviated)

form @parent_object do |parent_form|     ### In the controller I just pass @parent_object = Parent_object.new  (AR takes care of all the associations)
... the address sections

parent_form.fields_for :addresses do |primary|
primary.text_field :address_line_1
primary.hidden_field :address_type_id, :value => 'primary'
.... end


parent_form.fields_for :addresses do |alternative|
alternative.text_field :address_line_1
alternative.hidden_field :address_type_id, :value => 'alternative'
.... end

I think this may work.  Haven't looked at the params yet...


--
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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/94eb6860-5fbb-4b06-9cd9-d70de2098c3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment