What does the HTML that gets generated look like?
This is what is generated (according to firebug):
<div id="add_milestone">
<input id="customer_account_events__event_type_id" type="hidden"
value="3" name="customer_account[events][][event_type_id]"/>
<input id="customer_account_events__is_active" type="hidden"
value="true" name="customer_account[events][][is_active]"/>
<input id="customer_account_events__user_id" type="hidden" value="1"
name="customer_account[events][][user_id]"/>
<table class="account" border="1" width="80%">
<tbody>
<tr>
<td width="5%">Milestone </td>
<td width="15%">
<input id="customer_account_events__eta" type="text" style="width:
98%;" size="30" name="customer_account[events][][eta]"/>
<img style="border: 0px none ; cursor: pointer;" src="/images/
calendar_date_select/calendar.gif?1213626238" onclick="new
CalendarDateSelect( $(this).previous(), {time:true, year_range:10} );"
alt="Calendar"/>
</td>
<td width="36%">
<textarea id="customer_account_events__description" class="full-width"
rows="2" name="customer_account[events][][description]" cols="40"/>
</td>
<td width="8%">
<select id="customer_account_events__risk_level_id" class="full-width"
name="customer_account[events][][risk_level_id]">
</select>
</td>
<td width="36%">
<textarea id="customer_account_events__risk_description" class="full-
width" rows="2" name="customer_account[events][][risk_description]"
cols="40"/>
</td>
</tr>
</tbody>
</table>
<a onclick="Element.extend(this).up($('.add_milestone')).remove();
return false;" href="#">(remove new milestone)</a>
</div>
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.
On Sep 16, 1:56 pm, "Pardee, Roy" <[EMAIL PROTECTED]> wrote:
> 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]?
>
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
> Of Nathan R
> Sent: Tuesday, September 16, 2008 10:17 AM
> To: Ruby on Rails: Talk
>
> Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: [Rails] 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:
>
> <div id="add_milestone">
> </div>
> <%= 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:
>
> <div id="add_milestone">
>
> <% fields_for "customer_account[events][]", event do |events_form| %>
>
> <table class="account">
> <tr>
> <td >Milestone </td>
> <%= 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) %>
> <td ><%=events_form.calendar_date_select(:eta) </td>
> <td ><%= events_form.text_area(:description, :rows => 2, :class =>
> "full-width") %></td>
> <td > <%= events_form.collection_select(:risk_level_id,
> RiskLevel.find(:all), :id, :value, {:prompt => "- Select One -"},
> :class=>"full-width") %> </td>
> <td><%= events_form.text_area(:risk_description, :rows => 2, :class
> => "full-width") %></td>
> </tr>
>
> </table>
>
> <% end %>
>
> </div>
>
> 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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---