# Does collection\_select work in list.rhtml?

**URL:** <https://www.ruby-forum.com/t/does-collection-select-work-in-list-rhtml/111209>\
**Category:** Rails\
**Created:** [August 3, 2007, 8:43pm UTC](https://www.ruby-forum.com/t/does-collection-select-work-in-list-rhtml/111209 "2007-08-03T20:43:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arif](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/74df32/32.png) [@arif](https://www.ruby-forum.com/u/arif)\
**Post date:** [August 3, 2007, 8:43pm UTC](https://www.ruby-forum.com/t/does-collection-select-work-in-list-rhtml/111209/1 "2007-08-03T20:43:51Z")

</div>

Hi,  
I have 2 models:  
Model 1: er, Columns: \<er\_id, er\_name\>  
Model 2: er\_process, Columns: \<er\_id, er\_process\_name\>  
er\_id is a foreign key for Model 2.

When I am creating a new er\_process or editing an existing one, I have  
been successful to use collection\_select to show the available er’s so  
that the user can select a particular er by its name (to populate the  
er\_id field of er\_process), like this:

\<% form\_tag({:action =\> ‘create’}) do -%\>  
ER ID:   
\<%= collection\_select (“er\_process”, “er\_id”, Er.find(:all),  
“er\_id”, “er\_name”) %\>  
…  
\<% end %\>

But I have failed to do a similar thing in my list.rhtml page for  
er\_process. What I need is, provide the user with a ‘filter’ so that  
only the listing (of er\_process) with a particular er\_id is shown,  
based on what the user has selected as ‘er\_id’. I used this in my  
list.rhtml:

\<% form\_tag({:action =\> ‘search’}) do -%\>  
\<%= collection\_select (“er\_process”, “er\_id”, Er.find(:all),  
“er\_id”, “er\_name”) %\>  
\<%= submit\_tag(‘Filter by ER’) %\>  
…  
\<% end %\>

(I have a method ‘search’ in my controller that works fine).

The above is not working, giving me the error:  
undefined method `er\_id’ for #Array:0x4a78178

To my surprise, a text\_field\_tag is working:  
\<%= text\_field\_tag :er\_id, @er\_id, :size =\> 1 %\>

But this doesn’t fulfill my need as I want the user to select from a  
drop-down-list (using collection\_select).

Could anybody please help?  
Thanks.
