# Multiple fields\_for, same model

**URL:** <https://www.ruby-forum.com/t/multiple-fields-for-same-model/141008>\
**Category:** Rails\
**Created:** [June 20, 2008, 6:37pm UTC](https://www.ruby-forum.com/t/multiple-fields-for-same-model/141008 "2008-06-20T18:37:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nik\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ee59a6/32.png) [@Nik\_B](https://www.ruby-forum.com/u/Nik_B)\
**Post date:** [June 20, 2008, 6:37pm UTC](https://www.ruby-forum.com/t/multiple-fields-for-same-model/141008/1 "2008-06-20T18:37:19Z")

</div>

I have three fields\_for inside a form\_tag.

[http://pastie.org/218918](http://pastie.org/218918)

Two of them, correspond to the same model, :customer, (the two  
objects, billing\_customer and shipping\_customer have been built in the  
controller method). When I submit the form, the parameters only  
include one of the two fields\_for methods and it comes through as the  
model name, not the object name:

“customer”=\>{…}

I know there is a way to use two fields\_for sections that correspond  
to the same model… what am I doing wrong here?

-Nik

---

<div class="post-metadata">

**Author:** ![Nik\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ee59a6/32.png) [@Nik\_B](https://www.ruby-forum.com/u/Nik_B)\
**Post date:** [June 20, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/multiple-fields-for-same-model/141008/2 "2008-06-20T19:40:59Z")

</div>

Nik can you update mentioned URL with field names as well

try using following:  
\<% fields\_for :shipping\_customer do |sc| %\>  
\<%= sc.text\_field%\>  
\<% end %\>

```
    <% fields_for :billing do |bi| %>

```

…\<%= b.text\_field%\>  
\<% end %\>

\<% fields\_for :billing\_customer do |bc| %\>  
…\<%= bc.text\_field%\>  
\<% end %\>

MOdel:

ShippingCustomer.new(params[:shipping\_customer])  
Billing.new(params[:billing)  
ShippingCustomer.new(params[:billing\_customer)

I am using something like this and it is working for me.

let me know

Ajit

---

<div class="post-metadata">

**Author:** ![Nik\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ee59a6/32.png) [@Nik\_B](https://www.ruby-forum.com/u/Nik_B)\
**Post date:** [June 20, 2008, 7:50pm UTC](https://www.ruby-forum.com/t/multiple-fields-for-same-model/141008/3 "2008-06-20T19:50:23Z")

</div>

Just what I needed. Many thanks, Ajit.
