简体   繁体   English

如何使simple_form和bootstrap协同工作?

[英]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.

相关问题 如何让Ambethia Recaptcha与simple_form .error_notification一起使用? - How do I get Ambethia Recaptcha to work with simple_form .error_notification? 如何从头开始使用country_select gem和simple_form? - How do I get the country_select gem and simple_form to work from scratch? 您如何使用 Bootstrap 5 和 simple_form 编写切换开关 - How do you write a toggle switch with Bootstrap 5 and simple_form 你如何使枚举与simple_form一起工作? - how do you make enums work with simple_form? 如何显示错误消息以在集合选择工作simple_form上进行验证? - How do I display error messages for validation on a collection select work simple_form? 如何为bootstrap 3升级simple_form gem - how to upgrade simple_form gem for bootstrap 3 如何使用twitter-bootstrap-rails使simple_form工作; 一般在bootstrap中形成 - how to make simple_form work with twitter-bootstrap-rails; form in general in bootstrap 我如何摆脱将每个输入都包装在simple_form中的div? - How do I get rid of the div that wraps every input in a simple_form? 如何在simple_form中处理人员身高? - How do I handle person height within a simple_form? 如何使用simple_form从集合中返回对象? - How do I return the object from a collection with simple_form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM