int*_*boy 5 html ruby-on-rails
我有以下集合选择作为Rails应用程序中的过滤器.
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All'} %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
这总是会生成select元素的name属性,name="doctor[id]"这会导致浏览器?utf8=?&doctor%5Bid%5D=1无法读取.
如何将name属性更改为just name = "doctor"或基本上只是从中删除括号?
小智 7
collection_select方法包含参数"options"和"html_options"."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 %>
Run Code Online (Sandbox Code Playgroud)
你有没有尝试过:
<%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %>
<%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All', :name => 'doctor'} %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3692 次 |
| 最近记录: |