Adding Twitter bootstrap styling to Rails form helpers

后端 未结 2 700
时光取名叫无心
时光取名叫无心 2021-02-10 17:20

After reading the answer which suggested I use Simple_form gem with bootstrap integration, I installed it and created my form according to simple_form instructions, but the inpu

2条回答
  •  萌比男神i
    2021-02-10 18:02

    Rather than using the .form-actions class, which wraps the submit button in gray block (which might not work for your page design), you can also wrap the button in a control group like this:

      
    <%= f.button :submit %>

    This is only really needed if you're using the .form-horizontal class on the form itself.

    If you're looking for a drop-in replacement form builder that outputs bootstrap-style markup for Rails, you might want to check out a gem that I put together to handle this sort of thing:

    https://github.com/potenza/bootstrap_form

    Here's how you'd setup a horizontal-style form with the submit button properly lined up:

    <%= bootstrap_form_for(@user, html: { class: 'form-horizontal' }) do |f| %>
      <%= f.text_field :email %>
      <%= f.password_field :password %>
      <%= f.password_field :password_confirmation, label: 'Confirm Password' %>
      <%= f.control_group do %>
        <%= f.primary "Save User" %>
      <% end %>
    <% end %>
    

    This is the example output:

提交回复
热议问题