Using form-horizontal with simple_form in Rails 4

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:

1
2
3
4
5
6
<%= 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 someone!


Thanks for reading my post! If you enjoyed it or it helped you, please consider liking/tweeting this page, commenting, or following me on GitHub or Twitter!