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

后端 未结 2 933
北海茫月
北海茫月 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"}) %>
    
    0 讨论(0)
  • 2021-02-13 14:24

    This works for me:

    <%= f.select :secretquestion, options_for_select([
      ["Select One", ""], 
      "Your nick name", 
      "your schoool name", 
      "your love name", 
      "your comapnay name", 
      "your favourite website"]), 
      {}, { class: "form form-group form-control" } %>
    
    0 讨论(0)
提交回复
热议问题