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 %>

  <p>
    <%= f.label :artist %><br />
    <%= text_field_with_auto_complete :price, :artist, :autocomplete
=> "off", :size => "30" %>
  </p>.....
.....

        <% 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" %>
                        </p>
                <% end %>
        <% end %>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to