0

我想添加这个选项

:include_blank => 真

如何将其添加到此 select_tag?

 <%= select_tag :genre, options_for_select(Genre.all.map{ |g| [g.name, g.id] }) %>
4

2 回答 2

2

我在文档中找到了这个:

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

于 2013-01-04T20:54:06.083 回答
0

您可以将选项include_blankselect_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 %>
于 2013-06-11T10:24:28.617 回答