# Form\_for and belongs\_to

**URL:** <https://www.ruby-forum.com/t/form-for-and-belongs-to/127419>\
**Category:** Rails\
**Created:** [January 29, 2008, 1:09am UTC](https://www.ruby-forum.com/t/form-for-and-belongs-to/127419 "2008-01-29T01:09:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![resident\_moron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5daacb/32.png) [@resident\_moron](https://www.ruby-forum.com/u/resident_moron)\
**Post date:** [January 29, 2008, 1:09am UTC](https://www.ruby-forum.com/t/form-for-and-belongs-to/127419/1 "2008-01-29T01:09:32Z")

</div>

Let’s say I have a simple RESTful scaffold named: product

and the new and edit forms contain something like:

\<% form\_for( @product ) do |f| %\>

\<%= f.text\_field :name %\>

\<% end %\>

Everything is cool and working. Now, let’s say I want to use a  
belongs\_to in product.rb

class Product

belongs\_to :some\_other\_model, blah, blah…

end

Is it possible to do something on the product form to reference  
some\_other\_model and capture form field values??

I’m thinking something along the lines of:

\<% form\_for( @product ) do |f| %\>

\<%= f.text\_field :some\_other\_model.other\_name %\>

\<% end %\>

or whatever the syntax would be…

Thanks

---

<div class="post-metadata">

**Author:** ![resident\_moron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5daacb/32.png) [@resident\_moron](https://www.ruby-forum.com/u/resident_moron)\
**Post date:** [January 29, 2008, 3:48am UTC](https://www.ruby-forum.com/t/form-for-and-belongs-to/127419/2 "2008-01-29T03:48:57Z")

</div>

you would wrap these in a fields\_for block. ie

\<% form\_for( @product ) do |f| %\>

\<%= f.text\_field :some\_other\_model.other\_name %\>

 \<% fields\_for :some\_other\_model do |o| %\> \<%= o.text\_field o.other\_name %\> \<% end %\> \<% end %\>
