Sahil Dave
2009-Feb-09 08:32 UTC
how to get form parameters while using fields_for with nested attributes
hi all.. i am trying to use *fields_for* to get and save nested attributes in a form. i have a ''Partner'' model associated with an ''Address'' model. partner has_many :addresses although the form is displaying fine, but on submitting it the following error is shown: *can''t convert HashWithIndifferentAccess into Array* on this line: *@partner = Partner.new(params[:partner])* the names of main ''partner'' fields are like: *partner[par_name]* the names of ''address'' fields are like: *partner[addresses][add_line_1]* *some code:* <% form_for(@partner) do |f| %> <%= f.error_messages %> <%= f.label :par_name, "Partner Name" %><br /> <%= f.text_field :par_name %> <% f.fields_for :addresses do |addr_fields| %> <p> <%= addr_fields.label :add_line_1, "Address Line 1" %><br /> <%= addr_fields.text_field :add_line_1 %> </p> <% end %> <%= f.submit "Create" %> <% end %> what''s wrong over here?? regards ------------- Sahil --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sazima
2009-Feb-09 13:07 UTC
Re: how to get form parameters while using fields_for with nested attributes
Take a look at the complex forms railscasts series (railscasts.com)... Cheers, Sazima On Feb 9, 6:32 am, Sahil Dave <sahil.dav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi all.. > > i am trying to use *fields_for* to get and save nested attributes in a form. > i have a ''Partner'' model associated with an ''Address'' model. > partner has_many :addresses > > although the form is displaying fine, but on submitting it the following > error is shown: > > *can''t convert HashWithIndifferentAccess into Array* > > on this line: > > *@partner = Partner.new(params[:partner])* > > the names of main ''partner'' fields are like: > > *partner[par_name]* > > the names of ''address'' fields are like: > > *partner[addresses][add_line_1]* > > *some code:* > > <% form_for(@partner) do |f| %> > <%= f.error_messages %> > <%= f.label :par_name, "Partner Name" %><br /> > <%= f.text_field :par_name %> > <% f.fields_for :addresses do |addr_fields| %> > <p> > <%= addr_fields.label :add_line_1, "Address Line 1" %><br /> > <%= addr_fields.text_field :add_line_1 %> > </p> > <% end %> > <%= f.submit "Create" %> > <% end %> > > what''s wrong over here?? > > regards > > ------------- > Sahil--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sahil Dave
2009-Feb-10 08:56 UTC
Re: how to get form parameters while using fields_for with nested attributes
On Feb 9, 6:07 pm, Sazima <rsaz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Take a look at the complex forms railscasts series (railscasts.com)... >thanx for the link.. now i am able to save an address along with a partner. but the partner_id (foreign key for partner) inside address table is not getting filled up. do i need to manually put the foreign key, if so how do i do it. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---