# Form params help

**URL:** <https://www.ruby-forum.com/t/form-params-help/68609>\
**Category:** Rails\
**Created:** [September 13, 2006, 10:12pm UTC](https://www.ruby-forum.com/t/form-params-help/68609 "2006-09-13T22:12:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/f04885/32.png) [@zaq](https://www.ruby-forum.com/u/zaq)\
**Post date:** [September 13, 2006, 10:12pm UTC](https://www.ruby-forum.com/t/form-params-help/68609/1 "2006-09-13T22:12:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zaq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/f04885/32.png) [@zaq](https://www.ruby-forum.com/u/zaq)\
**Post date:** [September 13, 2006, 10:26pm UTC](https://www.ruby-forum.com/t/form-params-help/68609/2 "2006-09-13T22:26:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zaq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/f04885/32.png) [@zaq](https://www.ruby-forum.com/u/zaq)\
**Post date:** [September 13, 2006, 11:33pm UTC](https://www.ruby-forum.com/t/form-params-help/68609/3 "2006-09-13T23:33:24Z")

</div>

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 %\>

---

<div class="post-metadata">

**Author:** ![zaq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/f04885/32.png) [@zaq](https://www.ruby-forum.com/u/zaq)\
**Post date:** [September 18, 2006, 7:03am UTC](https://www.ruby-forum.com/t/form-params-help/68609/4 "2006-09-18T07:03:05Z")

</div>

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.
