问题描述
我正在尝试使用简单形式和自举创建水平形式.我已经使用"rails generate simple_form:install"安装了引导程序.这就是我在html.erb
I am trying to create horizontal forms with simple-form and bootstrap. I have already installed bootstrap using "rails generate simple_form:install". This is what i have in html.erb
<%= simple_form_for(@company, :html => { :class => "form-horizontal" }) do |f| %>
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-4">
<%= f.input :name %>
</div>
</div>
但是表格仍然垂直显示.
But the form still appears vertically.
推荐答案
simple_form是生成引导程序表单的绝佳工具.但是,您需要做一些额外的工作才能使其与Bootstrap的 form-horizontal 类一起使用.
simple_form is a really great gem for generating bootstrap forms. However, you have to do a little extra to get it working with Bootstrap’s form-horizontal class.
自述文件未提及此信息,但它是内置的.只需这样编写表单声明即可:
The README doesn’t mention this, but it’s built in. Just write your form declaration like this:
<%= simple_form_for [:admin, @c], html: { class: 'form-horizontal' },wrapper: :horizontal_form do |f| %>
# ...form...
<% end %>
请注意包装器属性.自述文件中没有对此进行描述,因此我不得不仔细研究代码以弄清楚.
Note the wrapper attribute. This isn’t described in the README, and I had to dig through the code to figure it out.
希望这对您有所帮助!
这篇关于如何使用Twitter Bootstrap和Rails简单表单创建水平表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!