# Fields for grouping problem

**URL:** <https://www.ruby-forum.com/t/fields-for-grouping-problem/148745>\
**Category:** Rails\
**Created:** [September 16, 2008, 7:17pm UTC](https://www.ruby-forum.com/t/fields-for-grouping-problem/148745 "2008-09-16T19:17:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b9e5f3/32.png) [@Nathan\_R](https://www.ruby-forum.com/u/Nathan_R)\
**Post date:** [September 16, 2008, 7:17pm UTC](https://www.ruby-forum.com/t/fields-for-grouping-problem/148745/1 "2008-09-16T19:17:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nathan\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b9e5f3/32.png) [@Nathan\_R](https://www.ruby-forum.com/u/Nathan_R)\
**Post date:** [September 16, 2008, 8:09pm UTC](https://www.ruby-forum.com/t/fields-for-grouping-problem/148745/2 "2008-09-16T20:09:05Z")

</div>

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]?

---

<div class="post-metadata">

**Author:** ![Nathan\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b9e5f3/32.png) [@Nathan\_R](https://www.ruby-forum.com/u/Nathan_R)\
**Post date:** [September 16, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/fields-for-grouping-problem/148745/3 "2008-09-16T20:25:03Z")

</div>

What does the HTML that gets generated look like?

This is what is generated (according to firebug):

| Milestone | ![Calendar](https://www.ruby-forum.com/images/%0Acalendar_date_select/calendar.gif?1213626238) | | | |

(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.

---

<div class="post-metadata">

**Author:** ![Nathan\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b9e5f3/32.png) [@Nathan\_R](https://www.ruby-forum.com/u/Nathan_R)\
**Post date:** [September 16, 2008, 9:45pm UTC](https://www.ruby-forum.com/t/fields-for-grouping-problem/148745/4 "2008-09-16T21:45:15Z")

</div>

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… ☹
