Search code examples
ruby-on-rails-5search-form

Rails 5 dropdown prompt error using options_for_select


Quick one. Cannot seem to work this out or get it to work. I just want a placeholder of "Select Listing" in the dropdown instead of the first listing in the list. I've tried adding

prompt: 'Select Listing'

in between a few places but getting syntax errors. Any help be great. I know i'm doing something stupid.

<%= f.select :desk_id, options_for_select(@desks.collect {|u| [u.listing_name, u.id]}, params[:listing_name]), {}, {
 onchange: "$(this.form).submit()",
 class: "form-control"
 } %>

Thanks in advance.


Solution

  • Answer.

    <%= f.select :desk_id, options_for_select(@desks.collect {|u| [u.listing_name, u.id]}, params[:listing_name]), {include_blank: 'Select Something'}, {
            onchange: "$(this.form).submit()",
            class: "form-control"
            } %>