Unable to add & ldquo; Well & rdquo; Class to create an enrollment form (form_for) using Twitter Bootstrap

advertisements

Why doesn't the "well" class get displayed when the page is rendered?

<div class="container">
  <div class="row">
    <div class="offset4 span4">
      <h2>Sign up</h2>

      <%= form_for(resource, :html => { :class => "well" }, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
        <%= devise_error_messages! %>

        <div><%= f.label :email %><br />
        <%= f.email_field :email %></div>

        <div><%= f.label :password %><br />
        <%= f.password_field :password %></div>

        <div><%= f.label :password_confirmation %><br />
        <%= f.password_field :password_confirmation %></div>

        <div><%= f.submit "Sign up" %></div>
      <% end %>

      <%= render "devise/shared/links" %>
    </div>
  </div>
</div>

The form looks like this when rendered:

    <form method="post" id="new_user" class="new_user" action="/users" accept-charset="UTF-8"><div style="margin:0;padding:0;display:inline"><input type="hidden" value="✓" name="utf8"><input type="hidden" value="P3KHtU5CRNy0/kVEvck4coilSOWCHYaKPZ5D1xCxQj4=" name="authenticity_token"></div>

        <div><label for="user_email">Email</label><br>
        <input type="email" value="" size="30" name="user[email]" id="user_email"></div>

        <div><label for="user_password">Password</label><br>
        <input type="password" size="30" name="user[password]" id="user_password"></div>

        <div><label for="user_password_confirmation">Password confirmation</label><br>
        <input type="password" size="30" name="user[password_confirmation]" id="user_password_confirmation"></div>

        <div><input type="submit" value="Sign up" name="commit"></div>
</form>

Notice class is just "new_user". No "well", why and how do I fix it?

Thanks

UPDATE:

I've updated it to:

  <%= form_for(resource, :class => "well", :as => resource_name, :url => registration_path(resource_name)) do |f| %>

Rendered HTML:

<form method="post" id="new_user" class="new_user" action="/users" accept-charset="UTF-8"><div style="margin:0;padding:0;display:inline"><input type="hidden" value="✓" name="utf8"><input type="hidden" value="P3KHtU5CRNy0/kVEvck4coilSOWCHYaKPZ5D1xCxQj4=" name="authenticity_token"></div>

Still not working. Using Rails 3.2.8 Using HAML in the rest of the app even though these files are ERB. Could that be it?


Actually the reason why your form_for doesn't append the class is because with form_for, you need to state it inside a :html hash:

form_for(resource, :html => {:class => "well"}, :as => resource_name, :url => registration_path(resource_name)) do

api.rubyonrails.org form_for, read the paragraph describing the three hash options (:url, :namespace and :html)