How do I use the Bootstrap form select css with a Rails model?

后端 未结 2 932
北海茫月
北海茫月 2021-02-13 13:45

I want to use the Bootstrap css to style a \"select\" box in a form in a Ruby on Rails app.

On the Bootstrap site, they give this as an example:



        
2条回答
  •  情书的邮戳
    2021-02-13 14:03

    First of all, for bootstrap's form-control class to work, you must add it to select tag itself

    Per apidoc of rails form select

    select(object, method, choices = nil, options = {}, html_options = {}, &block)
    

    you can add html class as

    <%= f.select(:ampm, options_for_select([['AM', 1], ['PM', 2]]), {}, {class: "form-control"}) %>
    

    or simply

    <%= f.select :ampm, [['AM', 1], ['PM', 2]], {}, {class: "form-control"}) %>
    

提交回复
热议问题