# Complex forms and :index =\> nil issues

**URL:** <https://www.ruby-forum.com/t/complex-forms-and-index-nil-issues/161114>\
**Category:** Rails\
**Created:** [February 23, 2009, 4:57pm UTC](https://www.ruby-forum.com/t/complex-forms-and-index-nil-issues/161114 "2009-02-23T16:57:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sa125](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b4bc9f/32.png) [@sa125](https://www.ruby-forum.com/u/sa125)\
**Post date:** [February 23, 2009, 4:57pm UTC](https://www.ruby-forum.com/t/complex-forms-and-index-nil-issues/161114/1 "2009-02-23T16:57:32Z")

</div>

Hi - I’m trying to figure out how to group nested fields in the form  
such that they all submit with a certain order. I followed the complex  
forms railscast ([#75 Complex Forms Part 3 - RailsCasts](http://railscasts.com/episodes/75)), but I’m trying to  
submit a nested model with more than a single field.

\<% fields\_for ‘project[task\_attributes][]’, task do |tf| %\>

Name: \<%= tf.text\_field :name, :index =\> nil %\>

Start: \<%= tf.text\_field :start, :index =\> nil %\>

End: \<%= tf.text\_field :end, :index =\> nil %\>

\<% unless task.new\_record? %\>  
\<% tf.hidden\_field :id, :index =\> nil %\>  
\<% end %\>

\<% end -%\>

When I submit, params looks strange and is completely disorganized:

{ “project” =\>  
{ “name” =\> “test”,  
“task\_attributes” =\> [{ “start” =\> “10:00” },  
{ “start” =\> “12:00” },  
{ “end” =\> “10:30”, “start” =\> “11:00” },  
{ “end” =\> “11:30” },  
{ “end” =\> “12:30”, “id” =\> “1” },  
{ “id” =\> “2”, “name” =\> “mow lawn” },  
{ “name” =\> “buy milk” },  
{ “name” =\> “clean room” }] }}

If I ommit the :index =\> :nil, I get an error “conflicting types for  
parameter containers. Expected an instance of Array but found an  
instance of Hash” called on task\_attribues. What I need is exactly that

- a hash grouping each task by id with it’s attributes:  
{ “task\_attributes” =\>  
{ “1” =\> { “name” =\> ‘buy milk’,  
“start” =\> ‘10:00’,  
“end” =\> ‘10:30’ }  
“2” =\> {…}…}

I’m feeling like I’m missing something big here… Any help will be  
great - thanks.

---

<div class="post-metadata">

**Author:** ![sa125](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b4bc9f/32.png) [@sa125](https://www.ruby-forum.com/u/sa125)\
**Post date:** [February 23, 2009, 5:19pm UTC](https://www.ruby-forum.com/t/complex-forms-and-index-nil-issues/161114/2 "2009-02-23T17:19:50Z")

</div>

On 23 Feb 2009, at 15:57, sa 125 wrote:

> ```
> { "id" => "2", "name" => "mow lawn" },
> 
> ```
> 
> { “1” =\> { “name” =\> ‘buy milk’,  
> “start” =\> ‘10:00’,  
> “end” =\> ‘10:30’ }  
> “2” =\> {…}…}

I’m guessing the problem here is new records ? the easiest way out of  
here is to drop all the :index =\> nil, but if the record is new the  
call fields\_for …, :index =\> ‘something’

new records would then appear with that key in the task\_attributes  
hash (obviously make the index unique)

Fred

---

<div class="post-metadata">

**Author:** ![sa125](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b4bc9f/32.png) [@sa125](https://www.ruby-forum.com/u/sa125)\
**Post date:** [February 24, 2009, 1:59pm UTC](https://www.ruby-forum.com/t/complex-forms-and-index-nil-issues/161114/3 "2009-02-24T13:59:41Z")

</div>

Frederick C. wrote:

> On 23 Feb 2009, at 15:57, sa 125 wrote:
> 
> > ```
> > { "id" => "2", "name" => "mow lawn" },
> > 
> > ```
> > 
> > { “1” =\> { “name” =\> ‘buy milk’,  
> > “start” =\> ‘10:00’,  
> > “end” =\> ‘10:30’ }  
> > “2” =\> {…}…}
> 
> I’m guessing the problem here is new records ? the easiest way out of  
> here is to drop all the :index =\> nil, but if the record is new the  
> call fields\_for …, :index =\> ‘something’
> 
> new records would then appear with that key in the task\_attributes  
> hash (obviously make the index unique)
> 
> Fred

I did as you proposed and seperated the new record from the edited one.  
I get the hash I wanted indexed by id (for edit), but apparently rails  
doesn’t like it and throws an error:

Conflicting types for parameter containers. Expected an instance of  
Array but found an instance of Hash…

---

<div class="post-metadata">

**Author:** ![sa125](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b4bc9f/32.png) [@sa125](https://www.ruby-forum.com/u/sa125)\
**Post date:** [February 25, 2009, 9:59am UTC](https://www.ruby-forum.com/t/complex-forms-and-index-nil-issues/161114/4 "2009-02-25T09:59:22Z")

</div>

I read that rails 2.3 will handle nested models seamlessly with  
accepts\_nested\_attributes\_for inside the parent model  
([Ruby on Rails 2.3 Release Notes — Ruby on Rails Guides](http://guides.rubyonrails.org/2_3_release_notes.html)).

Any idea when the final 2.3 is going to be released (currently in RC1)?
