在options_from_collection_for_select的下拉列表中留空

时间:2016-04-21 07:06:34

标签: ruby-on-rails ruby

我希望使用options_from_collection_for_select在我的下拉列表中包含空格,但似乎无法放入通常的集合参数{ :include_blank => true}。我无法在任何地方找到这方面的参考。我错过了什么吗?我的发言是:

<%= select_tag "search", options_from_collection_for_select(TaskGroup.all.order("LOWER(task_group_name)"), "id", "task_group_name",params[:search]) %>

提前感谢您的帮助,

利亚

2 个答案:

答案 0 :(得分:4)

试试这个:

<%= select_tag "search", options_from_collection_for_select(TaskGroup.all.order("LOWER(task_group_name)"), "id", "task_group_name",params[:search]), :include_blank => true %>

答案 1 :(得分:0)

试试这个:

<%= select_tag "search", options_for_select(TaskGroup.all.order("LOWER(task_group_name)").map {|task_group| [task_group.task_group_name, task_group.id]}, params[:search]), {include_blank: "Select task group"} %>