[英]How do I get simple_form and bootstrap to work together?
I'm using simple_form
to generate my forms in my Rails application. 我正在使用simple_form
在Rails应用程序中生成表单。 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
. 因此,我已经安装了以下gem,并将它们添加到我的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
. 最后,按照我运行的simple_form git页面上的说明, rails generate simple_form:install --bootstrap
。
After running bundle install
everything is installed and the server runs. 运行bundle install
后, bundle install
所有内容并运行服务器。 The forms however are still not displaying correctly as they would with the class "form-control". 但是,表单仍然无法像使用“ 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" } }
. 首先,我可以在每个输入中添加, class: "form-control"
,或者可以将其添加到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! 谢谢!
Probably you forgot about adding bootstrap assets to application.css file simple_form Readme has following line: 可能您忘记了将引导程序资产添加到application.css文件simple_form自述文件中的以下行:
You have to be sure that you added a copy of the Bootstrap assets on your application. 您必须确保在应用程序上添加了Bootstrap资产的副本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.