Rails: How to set up a collection?

I am trying to set up a search / filter using collection_select.

First: It works. It lists all cases for an employee with id = 15

.

<%= form_tag(cases_path, :method => "get") do %>
  <%= hidden_field_tag :param_e, 15 %>
  <%= submit_tag "Filter", :name => nil %>
<% end %>

      

But I want collection_select

, so I can list cases for any employee.

<%= form_tag(cases_path, :method => "get") do %>
  <%= collection_select( :x, :y, Employee.all, :id, :name, {}, { :multiple => false }) %>
  <%= hidden_field_tag :param_e, :z %>
  <%= submit_tag "Filter", :name => nil %>
<% end %>

      

Shown here collection_select

with all employees in the dropdown.

How to connect to collection_select?

+3


source to share





All Articles