我有以下集合选择,它在Rails应用程序中充当过滤器。
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All'} %>
<% end %>
这总是会生成select name="doctor[id]"
之类的select元素的name属性,从而导致浏览器显示?utf8=✓&doctor%5Bid%5D=1
,而且不太可读。
如何将name属性更改为name = "doctor"
或基本上只删除括号?
答案 0 :(得分:7)
collection_select方法包含参数“options”和“html_options”。 “选项”允许您添加特定信息,例如{:include_blank => 'All'}
,但不替换html属性。
您必须将名称添加到下一个哈希,如下所示:
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All'}, {:name => 'doctor'} %>
<% end %>
答案 1 :(得分:0)
你试过了吗?
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All', :name => 'doctor'} %>
<% end %>