Fields for grouping problem

So I am having a weird issue that I hope someone else has run into and
knows how to fix. Basically, I have a partial which includes a
fields_for call that renders a form for a specific type of object.
This partial can be rendered multiple times on a page if the user
wants to add multiple of these objects. However, when the submit
button is clicked, the grouping of the objects parameters are
inconsistent with how they are entered.

The result of trying to create two of these “event” objects follows:

Here is what the params hash contains on the request:

“events”=>[{“event_type_id”=>“3”},
{“event_type_id”=>“3”,
“is_active”=>“true”},
{“is_active”=>“true”,
“user_id”=>“1”},
{“eta”=>“September 22,
2008 1:11 PM”,
“user_id”=>“1”},
{“description”=>“Milestone 1 criteria”,
“eta”=>“September 23,
2008 1:11 PM”},
{“description”=>“Milestone 2 criteria”,
“risk_level_id”=>“1”},
{“risk_description”=>“Milestone 1 risk detail”,
“risk_level_id”=>“2”},
{“risk_description”=>“Milestone 2 risk detail”}]},
“commit”=>“Submit Changes”,
“authenticity_token”=>“af7a84442defabeeda94dac616930e9a3ee514d7”,
“id”=>“119”}

This is where the Partial is called in the view:

<%= add_milestone_link("Add a Milestone")%>

This is the helper method:

def add_milestone_link(name)
link_to_function name do |page|
page.insert_html :bottom,
:add_milestone,
:partial=>’/customer_accounts/edit_page/
add_milestone_event’,
:locals=>{:customer_account_id =>
@customer_account.id, :event=>Event.new}
end
end

This is the partial:

<% fields_for "customer_account[events][]", event do |events_form|

%>

<%= events_form.hidden_field(:event_type_id, :value =>

EventType.find_event_type_id_by_description(“Milestone”)) %>
<%= events_form.hidden_field(:is_active, :value => true) %>
<%= events_form.hidden_field(:user_id, :value =>
@current_user.id) %>





Milestone <%=events_form.calendar_date_select(:eta) <%= events_form.text_area(:description, :rows => 2, :class
=> “full-width”) %>
<%= events_form.collection_select(:risk_level_id,
RiskLevel.find(:all), :id, :value, {:prompt => “- Select One
-”}, :class=>“full-width”) %>
<%= events_form.text_area(:risk_description, :rows =>
2, :class => “full-width”) %>

<% end %>

Any help would be greatly appreciated as we have a similar problem
elsewhere in the code and the reason for this error should provide us
with the insight to fix that one as well

Nothing obviously wrong in your code (AFAIK, which isn’t very far ;-).
What does the HTML that gets generated look like? Are the name
attributes of your form_for generated input items things like:
customer_account[events][][is_active]?

What does the HTML that gets generated look like?

This is what is generated (according to firebug):

Milestone Calendar
(remove new milestone)

I’m thinking there might be a problem with where the hidden fields are
located, but i am not sure.

Are the name attributes of your form_for generated input items things
like: customer_account[events][][is_active]?
Yes, they all seem to be in order.

Those self-closing textarea tags look strange to me. Is that valid
HTML? When I tuck that blob of html in a I
don’t get something FF or IE will render correctly.

Not that I could tell you why the text_area form helper would produce
that code, mind you… :frowning: