Ruby on rails 如何添加';:包括_blank=>;正确';要自定义选择_标签?
我想添加这个选项 :include_blank=>true 如何将其添加到此选择标签Ruby on rails 如何添加';:包括_blank=>;正确';要自定义选择_标签?,ruby-on-rails,ruby-on-rails-3,view,Ruby On Rails,Ruby On Rails 3,View,我想添加这个选项 :include_blank=>true 如何将其添加到此选择标签 <%= 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 somet
<%= 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"
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>
因此使用:prompt=>“blank prompt”
你的可能是这样的:
select_tag :genre, options_from_collection_for_select(Genre.all.map{ |g| [g.name, g.id] }, "id", "name"), :prompt => "Select something"
此处的文档:
查看选择标签您可以将选项
包含空白
与选择标签
一起使用
从文件中:
select_tag "people", options_from_collection_for_select(@people, "id", "name"), :prompt => "Select something"
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>