In the example below we are passing a @user variable, but you can also pass something like this:
<%= form_for User.new, :url => { :controller => “users”, :action => “create” }, :html => {:class => “whatever_class_needed”} do |f| %>
And now, the example:
<%= form_for(@user) do |f| %><%= f.label :name %>
<%= f.text_field :name %><%= f.label :email %>
<%= f.text_field :email %><%= f.label :password %>
<%= f.password_field :password %><%= f.label :password_confirmation, “Confirmation” %>
<%= f.password_field :password_confirmation %>
<%= f.text_field :name %><%= f.label :email %>
<%= f.text_field :email %><%= f.label :password %>
<%= f.password_field :password %><%= f.label :password_confirmation, “Confirmation” %>
<%= f.password_field :password_confirmation %>
<%= f.submit “Create my account”, class: “btn btn-large btn-primary” %>
<% end %>
If you want to also include the error messages:
<%= render ‘shared/error_messages’ %>
In your shared directory, you have a partial that handles that:
<% if @user.errors.any? %>
<div id=”error_explanation”>
<div class=”alert alert-error”>
The form contains <%= pluralize(@user.errors.count, “error”) %>.
</div>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div id=”error_explanation”>
<div class=”alert alert-error”>
The form contains <%= pluralize(@user.errors.count, “error”) %>.
</div>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
Where @user is the controller variable driving your form
If you need to style the error messages differently (than the default red), you can modify the following stylesheet:
app/assets/stylesheets/scaffold.css.scss