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 -%> <label for="er_id">ER ID: </label> <%= 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.