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
ruby-on-rails ruby-on-rails-4


source to share


No one has answered this question yet

Check out similar questions:

1339
How can I rename a database column in Ruby on Rails migrations?
1023
How do I get the current absolute url in Ruby on Rails?
941
Understanding Rails Authentication ID
876
Brief explanation of nil v. Empty v. Blank in Ruby on Rails
596
How to use problems in Rails 4
1
Getting the value of an object in a select collection
1
rails: needs some explanation of collection_select
0
rails 4, collection_select, pass more than one attribute in parameter hash on form submit?
0
How to grab a selection from collection_select
0
Rails - use collection_select in simple_form for has_many_through association



All Articles
Loading...
X
Show
Funny
Dev
Pics