简体   繁体   English

如何将Rails表单代码添加到Bootstrap CSS

[英]How do I add rails form code to bootstrap css

I'm trying to style a simple Ruby on rails form with the Twitter Bootstrap css but I'm struggling to workout which bits of rails code goes into which part of the Bootstrap css for a form. 我正在尝试使用Twitter Bootstrap css样式化一个简单的Ruby on rails表单,但我正在努力锻炼表单的Bootstrap css的哪一部分进入了哪条rails代码。

For example where would the following line fit into the Bootstrap css for a form? 例如,以下哪行适合表单的Bootstrap CSS? :

<%= f.text_field :company %>

Based on the examples in the Twitter Bootstrap documentation, I am assuming you are attempting to apply the form-control class to your input. 基于Twitter Bootstrap文档中的示例,我假设您正在尝试将表单控件类应用于您的输入。 If this is the case, you would do it like this. 如果是这种情况,您可以这样做。

<%= f.text_field :company, :class => "form-control" %>

See similar question: Using CSS to style Ruby objects in erb 看到类似的问题: 使用CSS在erb中设置Ruby对象的样式

<%= f.text_field :company %>

Actually, this code means "Create a markup input of type text, with the good name (ex: user[company]) so Rails can handle the parameter easily". 实际上,这段代码的意思是“使用好名(例如:user [company])创建文本类型的标记输入,以便Rails可以轻松处理该参数”。 No more no less. 不多不少。

Example Output: 示例输出:

<input type="text" name="user[company]">

Bootstrap will envelope then this object with a style provided by CSS. Bootstrap将使用CSS提供的样式来封装该对象。 So 所以

1- Ensure your css is loaded into your "application.css" 1-确保您的CSS已加载到“ application.css”中

Usually, you'll need to add style for the form 通常,您需要为表单添加样式

  <%= form_for @resource, html: { class: "form form-inlined" }  do |f| %>

And also around your input text field: 以及您输入的文本字段周围:

  <div class="form-group">
     <%= f.label :company %>
     <%= f.text_field  :company, class: "form-input" %>
  </div>

This is just an example, but you can see where to put the bootstrap class on each elements. 这只是一个示例,但是您可以看到将bootstrap类放在每个元素上的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM