5

我有以下集合选择,它充当 Rails 应用程序中的过滤器。

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

这总是会生成 select 元素的 name 属性,name="doctor[id]"这会导致浏览器变为?utf8=✓&amp;doctor%5Bid%5D=1,这不太可读。

如何将 name 属性更改为只是name = "doctor"或基本上只是从中删除括号?

4

2 回答 2

7

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

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 %>
于 2013-10-10T00:53:52.227 回答
0

你有没有尝试过:

<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
    <%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All', :name => 'doctor'} %>
<% end %>
于 2013-05-02T03:08:38.207 回答