1

I have a simple_form like this

<%= simple_form_for(@name) do |f| %>
  <%= f.error_notification %>
  <div class="form-inputs">
    <%= f.input :fname %>
    <%= f.input :lname  %>
    <%= f.input :body %>        
  </div>

  <%= f.button :submit, 'submit' %>
<% end %>

and I want to make the label horizontal and apply other bootstrap code to it but I am not able to figure out how to do it since simple_form_for do not have any divs like form_for has.

Thanks

2 Answers 2

3

Its well explained on the gem website: https://github.com/plataformatec/simple_form

1) Generate the twitter bootstrap configuration for simpleform, by runnning:

rails generate simple_form:install --bootstrap

2) Follow the examples on the example application: https://github.com/rafaelfranca/simple_form-bootstrap/blob/master/app/views/articles/_form.html.erb

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

  <%- if f.error_notification %>
    <div class="alert alert-error fade in">
      <a class="close" data-dismiss="alert" href="#">&times;</a>
      <%= f.error_notification %>
    </div>
  <%- end %>

  <div class="form-inputs">
    <%= f.input :fname %>
    <%= f.input :lname  %>
    <%= f.input :body %>        
  </div>

<% end %>
Sign up to request clarification or add additional context in comments.

Comments

1

From the simple_form docs

SimpleForm can be easily integrated to the Twitter Bootstrap. To do that you have to use the bootstrap option in the install generator, like this:

rails generate simple_form:install --bootstrap

You have to be sure that you added a copy of the Twitter Bootstrap assets on your application.

For more information see the generator output, our example application code and the live example app.

NOTE: SimpleForm integration requires Twitter Bootstrap version 2.0 or higher.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.