Rails collection_select custom name attribute

I have the following selection of a collection that acts like a filter in a Rails application.

<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
   <%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All'} %>
<% end %>

This always generates an attribute attribute name for the select element, for example name="doctor[id]", which causes the browser to have ?utf8=✓&doctor%5Bid%5D=1something that is not entirely readable.

How to change name attribute only to name = "doctor"or just remove brackets from it?

+5
source share
2 answers

http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select

The collection_select method contains the options and html_options parameters. "Parameters" allow you to add certain information, for example {:include_blank => 'All'}, but do not replace html attributes.

, :

<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
   <%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All'}, {:name => 'doctor'} %>
<% end %>
+6

:

<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
    <%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All', :name => 'doctor'} %>
<% end %>
0

All Articles