轨道上的红宝石 - 如何将':include_blank => true'添加到自定义select_tag?



我想添加这个选项

:include_blank => true

我怎么能把它添加到这个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 => "blank 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_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 %>

相关内容

  • 没有找到相关文章

最新更新