Reputation: 886
I have the following collection select which acts as a filter in a Rails app.
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All'} %>
<% end %>
This always generates a name attribute of the select element like name="doctor[id]"
which results in the browser to ?utf8=✓&doctor%5Bid%5D=1
, which is not quite readable.
How can I change the name attribute to just name = "doctor"
or basically just remove the brackets from it?
Upvotes: 5
Views: 4922
Reputation: 71
The collection_select method contains the parameters "options" and "html_options". "options" allow you to add specific information, like {:include_blank => 'All'}
, but does not replace html attributes.
You have to add the name to the next hash, like this:
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All'}, {:name => 'doctor'} %>
<% end %>
Upvotes: 7
Reputation: 1534
Have you tried:
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All', :name => 'doctor'} %>
<% end %>
Upvotes: 0