3

I use bootstrap_form_for to create forms and have a collection select, where I want to add a custom class. I tried this, but this does not work:

<%= f.collection_select :location, Location.all, :id, :name, label: 'Location', :include_blank => ("Select..."), hide_label: true, :class => 'location' %>

Any ideas?

almo
  • 6,107
  • 6
  • 43
  • 86
  • 2
    Try `<%= f.collection_select :location, Location.all, :id, :name, {}, {class: "location"}` (possible duplicate of http://stackoverflow.com/questions/1947578/how-do-i-set-the-html-options-for-collection-select-in-rails) – Kevin Etore Jan 12 '17 at 16:07
  • Hey Kevin, make this an actual answer so I can give you an additional upvote. And thank you. – Jonathon Nordquist Mar 20 '17 at 23:40

1 Answers1

0

Many Rails helpers take multiple hash arguments.

And the definition of this collection_select method looks like this:

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})

So your select field will be:

<%= f.collection_select :location, Location.all, :id, :name,
    {label: 'Location', :include_blank => ("Select..."), hide_label: true}, {class: "location"} %>
Saqib Shahzad
  • 982
  • 12
  • 28