Is there a way to replace a text_field_tag with a select in a rails3 search function?
My current search form:
<%= form_tag orders_path, :method => 'get', :id => "orders_search" do %>
<p><%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %></p>
I wanted to replace with a dropdown to limit / filter my customers results. I’ve tried this:
<%= select :search, params[:search], ([["Pending"], ["Open"], ["Closed"]]) %>
However this gives me a 500 error and an output in the log:
TypeError (expected Array (got String) for param `search'):
I’ve also tried:
<%= select :search, ([["Pending"], ["Open"], ["Closed]]) %>
Which leads to an invalid number of arguments.
What’s the best way to do this?
Check Select helper methods in Ruby on Rails out.
You can probably do what you need with:
— EDIT —
In order to submit form on select add following in your application.js (provided you use jQuery):
There are already few stack overflow answers in regards to this.