# Send a collection from view to controller

**URL:** <https://www.ruby-forum.com/t/send-a-collection-from-view-to-controller/163994>\
**Category:** Rails\
**Created:** [March 26, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/send-a-collection-from-view-to-controller/163994 "2009-03-26T18:21:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@hiro](https://www.ruby-forum.com/u/hiro)\
**Post date:** [March 26, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/send-a-collection-from-view-to-controller/163994/1 "2009-03-26T18:21:08Z")

</div>

Hi everybody,

Maybe this is a sort of newbie question but I’ve been trying to solve  
it for several days without a solution.

Basically what I want to do is to pass a collection from the view to  
my controller. I paste here the relevant part of both.

Controller:

@member=Member.find(:all)

if params[:new\_member]=nil  
@list=[]  
@list.push(Member.new)  
else  
@list=params[‘list’]  
@list.push(Member.find(params[:new\_member]))  
end

View:

Inside a form that redirects to the controller

 \<%=member.name\> \<%end%\>

\<%=submit\_tag(“Add”)%\>

\<%= hidden\_field “list”, @list %\> # [1]

[1] Here’s the problem. The error I got is

“undefined method `push’ for {”#\<User:  
0xb7086210\>"=\>""}:HashWithIndifferentAccess"

But more important in parameters[error log]:

```
""list"=>{"#<User:0xb7086210>"=>""}}"

```

It means that the params[‘list’] value is taken as @list.name [that is  
just garbage]

I Hope someone can help me! Thanks!

---

<div class="post-metadata">

**Author:** ![hiro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@hiro](https://www.ruby-forum.com/u/hiro)\
**Post date:** [March 27, 2009, 2:54pm UTC](https://www.ruby-forum.com/t/send-a-collection-from-view-to-controller/163994/2 "2009-03-27T14:54:17Z")

</div>

First, the comparison between params[:new\_member] and nil should use  
“==”  
if nil == params[:new\_member]

---

<div class="post-metadata">

**Author:** ![hiro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@hiro](https://www.ruby-forum.com/u/hiro)\
**Post date:** [March 27, 2009, 4:50pm UTC](https://www.ruby-forum.com/t/send-a-collection-from-view-to-controller/163994/3 "2009-03-27T16:50:32Z")

</div>

On Mar 27, 8:53 am, Phillip \<p…@phillip [harris.com](http://harris.com)\> wrote:

> First, the comparison between params[:new\_member] and nil should use  
> “==”  
> if nil == params[:new\_member]

Yes you’re right It was a typing error here in the post. But I still  
have this problem I hope so can help me.

---

<div class="post-metadata">

**Author:** ![hiro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5ac83/32.png) [@hiro](https://www.ruby-forum.com/u/hiro)\
**Post date:** [March 27, 2009, 5:01pm UTC](https://www.ruby-forum.com/t/send-a-collection-from-view-to-controller/163994/4 "2009-03-27T17:01:41Z")

</div>

Have a look in the log to see what the parameters are, particularly  
params[:list]. I think your code is assuming it is an array but the  
error  
suggests otherwise. Also have a look in the debugger to what is what.  
Also  
the source of the web page may be informative.

2009/3/27 Hiro [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
