Problem with text_field and []

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs