# Problem with text\_field and \[\]

**URL:** <https://www.ruby-forum.com/t/problem-with-text-field-and/114315>\
**Category:** Rails\
**Created:** [September 11, 2007, 10:00am UTC](https://www.ruby-forum.com/t/problem-with-text-field-and/114315 "2007-09-11T10:00:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stebi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/bbce88/32.png) [@stebi](https://www.ruby-forum.com/u/stebi)\
**Post date:** [September 11, 2007, 10:00am UTC](https://www.ruby-forum.com/t/problem-with-text-field-and/114315/1 "2007-09-11T10:00:49Z")

</div>

Hi,

I was pleased to see how easy it is to add more then one new items in a  
form:

form\_tag :action =\> ‘update\_multiple’ do  
3.times do  
@item = Item.new # create an active record object  
text\_field ‘item[]’, ‘name’  
end  
end

the action “update\_multiple” now gets a list of the three items  
(params[:item]). Wonderful.

It even works for already known items / items from the database:

form\_tag :action =\> ‘update\_multiple’ do  
@item = Item.find(1)  
text\_field ‘item[]’, ‘name’

@item = Item.find(2)  
text\_field ‘item[]’, ‘name’

@item = Item.find(3)  
text\_field ‘item[]’, ‘name’  
end

Here also “update\_multiple” gets the list…

…but I would not post here if I don’t have a problem.

If I mix both using some new und some known items than I get an server  
error:

form\_tag :action =\> ‘update\_multiple’ do

# show some “old” items

@item = Item.find(1)  
text\_field ‘item[]’, ‘name’

@item = Item.find(2)  
text\_field ‘item[]’, ‘name’

# add three new items

3.times do  
@item = Item.new # create an active record object, which doesn’t  
have an id yet  
text\_field ‘item[]’, ‘name’  
end  
end

this leads to the error 500-message. When I look into the log file the  
following entry comes up:

* * *

Conflicting types for parameter containers. Expected an instance of  
Array, but found an instance of Hash. This can be caused by passing  
Array and Hash based paramters qs[]=value&qs[key]=value.

c:/programme/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/cgi\_ext/cgi\_methods.rb:204:in

`type\_conflict!’  
c:/programme/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/cgi\_ext/cgi\_methods.rb:168:in

`container’  
c:/programme/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/cgi\_ext/cgi\_methods.rb:155:in

`post\_key\_check’  
c:/programme/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/cgi\_ext/cgi\_methods.rb:134:in

`parse’  
c:/programme/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/cgi\_ext/cgi\_methods.rb:37:in

`parse\_request\_parameters’  
c:/programme/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/cgi\_ext/cgi\_methods.rb:28:in

`each’  
c:/programme/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action\_controller/cgi\_ext/cgi\_methods.rb:28:in

## `parse\_request\_parameters’ […]

How can I achieve that I can edit new as well as “old” items from a  
database? In my real application I want the user to edit a list of items  
and append some items (via ajax). When done the complete list (one form)  
is posted to the action.  
One solution is to have an id for the new items, but as there are not  
yet written to the database this must be a fictious id which is harder  
to handle.

Hope somebody can help me…Thanks in advance

Steffen
