Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blank in drop-down list in options_from_collection_for_select

I'd like to include a blank in my drop-down list using options_from_collection_for_select but cannot seem to put in the usual collection parameter { :include_blank => true}. I cannot find a reference for this anywhere. Am I missing something? My statement is:

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

Thanking you in advance for your help,

Leah

like image 832
user3331154 Avatar asked Apr 21 '16 07:04

user3331154


2 Answers

Try this:

<%= 
  select_tag( 
    "search",
    options_from_collection_for_select(
      TaskGroup.all.order("LOWER(task_group_name)"), "id", "task_group_name",params[:search]
    ), 
    :include_blank => true 
  )
%>
like image 64
dp7 Avatar answered Sep 29 '22 06:09

dp7


Try this:

<%= 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"} %>
like image 20
thanhnha1103 Avatar answered Sep 29 '22 07:09

thanhnha1103