Twitter-Bootstrap: Simple_form not making horizontal form or correct HTML output? Twitter-Bootstrap: Simple_form not making horizontal form or correct HTML output? ruby-on-rails ruby-on-rails

Twitter-Bootstrap: Simple_form not making horizontal form or correct HTML output?


Have you added the initializer for simple_form? this initializer sets the wrappers that should be used to output the bootstrap html

rails generate simple_form:install --bootstrap

Note that this only works with simple_form 2!


The output of

rails g simple_form:install --bootstrap

gives further instructions:

Inside your views, use the 'simple_form_for' with one of the Bootstrap formclasses, '.form-horizontal', '.form-inline', '.form-search' or'.form-vertical', as the following:  = simple_form_for(@user, :html => {:class => 'form-horizontal' }) do |form|

So you must add the :html => {:class => 'form-horizontal' } option to each _form.html file you want to change the form style. You can use 'form-search', 'form-inline', 'form-horizontal', or 'form-vertical' (the default).

To set the default form to horizontal, edit

lib/templates/erb/scaffold/_form.html.erb

and change the first line to this (using your preferred form class name):

<%%= simple_form_for(@<%= singular_table_name %>, :html => {:class => 'form-horizontal' } ) do |f| %>

For those using HAML, the file path and format will be different.


Is your form css set to "form-horizontal" in outputted HTML?

If not, I think you have to wrap the setting of :html :class in simple_form_for tag like this:

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), {:html => { :class => "form-horizontal" }} ) do |f| %>

Hope it helps.