问题
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?
回答1:
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"} %>
来源:https://stackoverflow.com/questions/41617681/add-class-to-bootstrap-form-for-collection-select-in-rails-5