Jump to content

The ultimate community for Ruby on Rails developers.


bootstrap_form_for worked incorrectly

bootstrap 3

  • Please log in to reply
1 reply to this topic

#1 dailammoc



  • Members
  • 38 posts
  • Location/

Posted 25 March 2014 - 04:27 PM

Today i update bootstrap in my project to 3.0, and I found some things differently from 2.3. For example, the sign up form was changed:




and here is code of this form:

<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>

<div class="row">
  <div class="span6 offset3">
    <%= bootstrap_form_for @user do |f| %>
      <%= render 'shared/error_messages', object: f.object %>

      <% f.label :name %>
      <%= f.text_field :name, placeholder: "Enter your name" %>

      <% f.label :email %>
      <%= f.text_field :email, placeholder: "Enter your email" %>

      <% f.label :password %>
      <%= f.password_field :password, placeholder: "Enter your pass" %>

      <% f.label :password_confirmation, "Confirmation" %>
      <%= f.password_field :password_confirmation, placeholder: "Confirmation" %>

      <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
    <% end %>

the origin code is:

<%= form_for @user do |f| %>

I searched google and got suggestions from several forums to change to bootstrap_form_for instead of form_for. Unfortunately, the form still didn't change.  So my question is what the differences between bootstrap 3.x and bootstrap 2.x and

#2 Jake Smith

Jake Smith


  • Members
  • 1 posts
  • LocationColorado

Posted 28 April 2014 - 03:36 AM



You are using old Bootstrap 2 syntax for your sizing of the form.  You can see that from Bootstrap 2 to Bootstrap 3, they changed the syntax of the grid system: http://getbootstrap.com/css/#grid


So basically instead of using: 

<div class="span6 offset3">

You would use something like this:

<div class="col-lg-offset-3 col-lg-5">

EDIT: I almost forgot!  Take any divs you have applied the old syntax to and just copy and paste into this application and it will do a really good job converting it to the Bootstrap 3 syntax :)  Here is the link: http://code.divshot....trap3_upgrader/


The following helper:


is only available if you have the bootstrap_form gem installed and in your applications Gemfile.  But I use it myself and I really recommend it.  Here is the link to the Github page in case you didn't already know about it: https://github.com/b...bootstrap-forms

Also tagged with one or more of these keywords: bootstrap 3

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users