Rails: include index with fields_for form helper
Posted
by Patrick Oscity
on Stack Overflow
See other posts from Stack Overflow
or by Patrick Oscity
Published on 2010-03-12T13:36:22Z
Indexed on
2010/03/12
14:37 UTC
Read the original article
Hit count: 241
ruby-on-rails
|webforms
i'm trying to build two models from one form by using the fields_for method. my code looks like this:
<% for scale in @event.scales %>
<% f.fields_for "scale[]", scale do |scale_form| %>
<p>
Scale<br />
<%= scale_form.label :name %>
<%= scale_form.text_field :name %>
<%= scale_form.label :price %>
<%= scale_form.text_field :price %>
</p>
<% end %>
<% end %>
but unfortunately the output html is missing the id's of the scales:
<p>
Scale<br />
<label for="event_scale__name">Name</label>
<input id="event_scale__name" name="event[scale][][name]" size="30" type="text" />
<label for="event_scale__price">Price</label>
<input id="event_scale__price" name="event[scale][][price]" size="30" type="text" />
</p>
...
here's the corresponding controller and model:
class EventsController < ApplicationController
...
def new
@event = Event.new
@providers = Provider.find(:all, :order => :name)
3.times { @event.scales.build }
respond_to do |format|
format.html
end
end
...
end
class Event < ActiveRecord::Base
has_many :scales
...
end
what am i doing wrong?
© Stack Overflow or respective owner