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:
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|
%>
Milestone | <%= events_form.hidden_field(:event_type_id, :value =><%=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