# Complex forms in a simpler way?

**URL:** <https://www.ruby-forum.com/t/complex-forms-in-a-simpler-way/167947>\
**Category:** Rails\
**Created:** [May 14, 2009, 11:14am UTC](https://www.ruby-forum.com/t/complex-forms-in-a-simpler-way/167947 "2009-05-14T11:14:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@holden](https://www.ruby-forum.com/u/holden)\
**Post date:** [May 14, 2009, 11:14am UTC](https://www.ruby-forum.com/t/complex-forms-in-a-simpler-way/167947/1 "2009-05-14T11:14:27Z")

</div>

I have a form which updates across several models, and most of the  
time what is covered is close to the railscast example (complex  
forms), for adding photos etc, but i have another example trying to  
use the field\_for for a seemingly one to one relationship…

ie My form has a bunch of fields in one model, but two fields for  
price both high and low in a second model. There can only be one  
price or high and low added per form, but it is not a one to one  
relationship because the price can change over time which is added  
externally.

How can I do this?

Thanks,

Model:

class Price \< ActiveRecord::Base  
has\_many :records  
has\_many :bubbles

Controller:

```
@price = Price.new
@price.bubbles.build

```

View:  
\<% form\_for @price do |f| %\>  
\<%= f.error\_messages %\>

\<%= f.label :artist %\>  
 \<%= text\_field\_with\_auto\_complete :price, :artist, :autocomplete =\> "off", :size =\> "30" %\>

..... .....

```
<% for bubble in @price.bubbles %>
<% fields_for "price[bubble]", bubble do |e| %>
    <p>
    <%= e.label :price %><br />
      <%= e.text_field :low, :size => "4" %>-<%=

```

e.text\_field :high, :size =\> “4” %\>

  
\<% end %\>  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![holden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e36b37/32.png) [@holden](https://www.ruby-forum.com/u/holden)\
**Post date:** [May 14, 2009, 3:18pm UTC](https://www.ruby-forum.com/t/complex-forms-in-a-simpler-way/167947/2 "2009-05-14T15:18:05Z")

</div>

Nevermind just did it thru the controller:

def new  
@price = Price.new  
@bubble = Bubble.new  
…

def create  
@price = Price.new(params[:price])  
@bubble = @price.bubbles.build(params[:bubble])  
…

view:  
\<% fields\_for :bubble do |e| %\>

\<%= e.label :price %\> $(10-25)  
  
$\<%= e.text\_field :low, :size =\> “4” %\>-\<%=  
e.text\_field :high, :size =\> “4” %\>

  
\<% end %\>
