Search code examples
ruby-on-railstwitter-bootstrapruby-on-rails-4simple-form

How do I get simple_form and bootstrap to work together?


I'm using simple_form to generate my forms in my Rails application. I'm wanting to use bootstrap with these forms. So I've installed the following gems and added them to my gemfile... (1)simple_form, (2)twitter-bootstrap-rails. Finally, per instructions on the simple_form git page I ran, rails generate simple_form:install --bootstrap.

After running bundle install everything is installed and the server runs. The forms however are still not displaying correctly as they would with the class "form-control".

Form

= simple_form_for @user, html: { multipart: :true, class: "form-horizontal" } do |f|
  = f.input :headshot_image, as: :file
  = f.input :remote_headshot_image_url, placeholder: "Image Url"
  = f.input :first_name, required: true
  = f.input :middle_name
  = f.input :last_name, required: true

I am able to get it to "work" by two different methods (neither of which I believe are correct). First I can add , class: "form-control" to each input, or I can add to the simple_form_for :defaults => { :input_html => { :class => "form-control" } }. The former which kinda defeats the purpose I believe, and the latter works, but it also applies the class to the file input which is not ideal.

Is there a setup step that I missed? Or have I done something incorrect. If I need to provide more information or left something out please let me know. Thanks!


Solution

  • Probably you forgot about adding bootstrap assets to application.css file simple_form Readme has following line:

    You have to be sure that you added a copy of the Bootstrap assets on your application.