我想添加这个选项
:include_blank => 真
如何将其添加到此 select_tag?
<%= select_tag :genre, options_for_select(Genre.all.map{ |g| [g.name, g.id] }) %>
我想添加这个选项
:include_blank => 真
如何将其添加到此 select_tag?
<%= select_tag :genre, options_for_select(Genre.all.map{ |g| [g.name, g.id] }) %>
我在文档中找到了这个:
select_tag "people", options_from_collection_for_select(@people, "id", "name"), :prompt => "Select something"
所以你使用 :prompt => "空白提示"
你的可能看起来像这样:
select_tag :genre, options_from_collection_for_select(Genre.all.map{ |g| [g.name, g.id] }, "id", "name"), :prompt => "Select something"
此处的文档:http ://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html 查看 select_tag
您可以将选项include_blank
与select_tag
.
从文档中:
select_tag "people", options_from_collection_for_select(@people, "id", "name"), :include_blank => true
# => <select id="people" name="people"><option value=""></option><option value="1">David</option></select>
或者您可以使用options_for_select
:
<%= select_tag column.name, options_for_select(Genre.all.map{ |g| [g.name, g.id] }), :include_blank => true %>