Form params help

I’ve got a form where I have several items (“packages”) listed and I
want to query a param that should contain all the “packages” from the
form in the controller. However I’m only getting the first item
returned.

a working example is HATBM checkboxes where

vs

how do I get the name="object[method][]

here’s the rhtml

<%= start_form_tag :action => ‘push’ %>
<% @packages.each do |p| %>
<%= hidden_field ‘package’, ‘Name’, :value => p.Name %>
<% end %>
<%= submit_tag “PushIT” %>
<%= end_form_tag %>

my controller (just a skeleton at the moment to debug

def push

@params = params
@pkgparams = params[:package][:Name]

end

my result is only the first package from the |p| loop.

How do I get multiple text fields to collect into a param with the same
name like a checkbox does?

thanks

-zac

<%= hidden_field ‘package[]’, ‘Name’, :value => p.Name %> i guess

Jean-Etienne D. wrote:

<%= hidden_field ‘package[]’, ‘Name’, :value => p.Name %> i guess

nope:
You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occured while evaluating nil.id_before_type_cast

32: <%= text_field ‘package[]’, ‘Name’, :value => p.Name %>

Zac E. wrote:

/>
<%= end_form_tag %>
my result is only the first package from the |p| loop.

How do I get multiple text fields to collect into a param with the same
name like a checkbox does?

<% @packages.each do |p| %>
<%= text_field_tag ‘package_names[]’, p.name %>
<% end %>

params[:package_names] will be an array of strings
when the form is posted.


We develop, watch us RoR, in numbers too big to ignore.