html – Rails collection_select自定义名称属性

html – Rails collection_select自定义名称属性,第1张

概述我有以下集合选择作为Rails应用程序中的过滤器. <%= form_tag( "/appointments", :method => "get", :id => "filter_form") do %> <%= collection_select :doctor, :id, @doctors, :id, :full_name, {:include_blank => 'All'} %><% 我有以下集合选择作为Rails应用程序中的过滤器.

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

这总是会生成select元素的name属性,例如name =“doctor [ID]”,这会导致浏览器输出?utf8 =✓& doctor [ID] = 1,这是不太可读的.

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

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

collection_select方法包含参数“options”和“HTML_options”. “选项”允许您添加特定信息,例如{:include_blank => ‘全部’},但不替换HTML属性.

您必须将名称添加到下一个哈希,如下所示:

<%= form_tag( "/appointments",{:include_blank => 'All'},{:name => 'doctor'} %><% end %>
总结

以上是内存溢出为你收集整理的html – Rails collection_select自定义名称属性全部内容,希望文章能够帮你解决html – Rails collection_select自定义名称属性所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1080155.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存