Add class to bootstrap_form_for collection_select in Rails 5

久未见 提交于 2020-01-02 08:42:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!