# How to get form parameters while using fields\_for with nested attributes

**URL:** <https://www.ruby-forum.com/t/how-to-get-form-parameters-while-using-fields-for-with-nested-attributes/159833>\
**Category:** Rails\
**Created:** [February 9, 2009, 9:32am UTC](https://www.ruby-forum.com/t/how-to-get-form-parameters-while-using-fields-for-with-nested-attributes/159833 "2009-02-09T09:32:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sahil\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sahil\_D](https://www.ruby-forum.com/u/Sahil_D)\
**Post date:** [February 9, 2009, 9:32am UTC](https://www.ruby-forum.com/t/how-to-get-form-parameters-while-using-fields-for-with-nested-attributes/159833/1 "2009-02-09T09:32:55Z")

</div>

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” %\>  
  
\<%= f.text\_field :par\_name %\>  
\<% f.fields\_for :addresses do |addr\_fields| %\>

\<%= addr\_fields.label :add\_line\_1, “Address Line 1” %\>  
  
\<%= addr\_fields.text\_field :add\_line\_1 %\>

  
\<% end %\>  
\<%= f.submit “Create” %\>  
\<% end %\>

what’s wrong over here??

regards

* * *

Sahil

---

<div class="post-metadata">

**Author:** ![Sahil\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sahil\_D](https://www.ruby-forum.com/u/Sahil_D)\
**Post date:** [February 9, 2009, 2:08pm UTC](https://www.ruby-forum.com/t/how-to-get-form-parameters-while-using-fields-for-with-nested-attributes/159833/2 "2009-02-09T14:08:38Z")

</div>

Take a look at the complex forms railscasts series ([railscasts.com](http://railscasts.com))…

Cheers, Sazima

---

<div class="post-metadata">

**Author:** ![Sahil\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee7513/32.png) [@Sahil\_D](https://www.ruby-forum.com/u/Sahil_D)\
**Post date:** [February 10, 2009, 9:57am UTC](https://www.ruby-forum.com/t/how-to-get-form-parameters-while-using-fields-for-with-nested-attributes/159833/3 "2009-02-10T09:57:58Z")

</div>

On Feb 9, 6:07 pm, Sazima [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Take a look at the complex forms railscasts series ([railscasts.com](http://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.
