How to create horizontal forms with twitter bootstrap and rails simple form

☆樱花仙子☆ 提交于 2021-02-20 18:49:21

问题


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.


回答1:


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.

Hope this helps you!



来源:https://stackoverflow.com/questions/48422959/how-to-create-horizontal-forms-with-twitter-bootstrap-and-rails-simple-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!