# Does collection\_select work in list.rhtml?

**URL:** <https://www.ruby-forum.com/t/does-collection-select-work-in-list-rhtml/111212>\
**Category:** Rails\
**Created:** [August 3, 2007, 9:09pm UTC](https://www.ruby-forum.com/t/does-collection-select-work-in-list-rhtml/111212 "2007-08-03T21:09:02Z")\
**Posts on this page:** 3\
**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, 9:09pm UTC](https://www.ruby-forum.com/t/does-collection-select-work-in-list-rhtml/111212/1 "2007-08-03T21:09:02Z")

</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.

---

<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:** [September 5, 2007, 12:10am UTC](https://www.ruby-forum.com/t/does-collection-select-work-in-list-rhtml/111212/2 "2007-09-05T00:10:44Z")

</div>

Hello,  
I’have the same problem , Have you found a solution . If you have  
please post.  
Meanwhile I’m trying to use aax to solve the problem…

---

<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:** [September 5, 2007, 12:17am UTC](https://www.ruby-forum.com/t/does-collection-select-work-in-list-rhtml/111212/3 "2007-09-05T00:17:45Z")

</div>

found a solution

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/e0e3e414ce943cc4/402ca7bac08abee3?lnk=gst&q=list+editing&rnum=8#402ca7bac08abee3](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/e0e3e414ce943cc4/402ca7bac08abee3?lnk=gst&q=list+editing&rnum=8#402ca7bac08abee3)
