# How can I use aggregation objects in form\_for?

**URL:** <https://www.ruby-forum.com/t/how-can-i-use-aggregation-objects-in-form-for/91896>\
**Category:** Rails\
**Created:** [April 13, 2007, 6:47am UTC](https://www.ruby-forum.com/t/how-can-i-use-aggregation-objects-in-form-for/91896 "2007-04-13T06:47:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![allen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@allen](https://www.ruby-forum.com/u/allen)\
**Post date:** [April 13, 2007, 6:47am UTC](https://www.ruby-forum.com/t/how-can-i-use-aggregation-objects-in-form-for/91896/1 "2007-04-13T06:47:45Z")

</div>

Say I have a person object which has a aggregation object call  
address. The the code to manipulate a form for create a new person  
should be:

# new.rhtml

\<% form\_for :person, :url =\> {:action =\> ‘create’} do |f| %\>  
\<%= render :partial =\> ‘form’, :locals =\> {:f =\> form} %\>  
\<%= submit\_tag “Create” %\>  
\<% end %\>

# \_form.rhtml

Name  
\<%= form.text\_field :name %\>

Country  
\<%= form.text\_field :country %\>

City  
\<%= form.text\_field :city %\>

This does work. But country and city belong to the aggregation object  
address and I want to use address in the form. According to RDoc and  
rails book. The above text\_field helper method will generate and rails will recognize it and translate it  
into :person =\> {:name}. And if I can generate something like , then rails will get :person =\>  
{:address =\> {:country}}, which is exactly what I want. How can I tell  
rails to generate this kind of input for me? I cannot find any  
information about this in RDoc. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![allen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/bbce88/32.png) [@allen](https://www.ruby-forum.com/u/allen)\
**Post date:** [April 13, 2007, 8:19am UTC](https://www.ruby-forum.com/t/how-can-i-use-aggregation-objects-in-form-for/91896/2 "2007-04-13T08:19:12Z")

</div>

There is ‘fields\_for’ which behaves the same as ‘form\_for’ but without  
wrapping the block in a form tag.

\<%= fields\_for @model.aggregation, … do |subform|%\>

\<% end %\>
