psoderberg edited this page Jan 4, 2015 · 13 revisions


Clearance is a Rails engine but it also asks the developer to include two modules. This is meant for override-ability.

Application controller example:

class ApplicationController < ActionController::Base
  include Clearance::Controller

User model example:

class User < ActiveRecord::Base
  include Clearance::User

The migration

The generator will also create a migration to add a “users” table and run it. If the table already exists in the database, the migration will just add fields and indexes that are missing and required by Clearance. If the migration fails, the generator will revert all changes back.


Clearance will add these routes:


get 'users/new'
post 'users'


get 'users/:user_id/confirmation/new'
post 'users/:user_id/confirmation'


get 'session/new'
post 'session'
delete 'session'


get 'users/:user_id/password/new'
post 'users/:user_id/password'
get 'users/:user_id/password/edit'
put 'users/:user_id/password'

The flash

You will need to display the success, failure, and notice flash messages in your layout. We recommend creating an app/views/layouts/_flashes.html.erb partial similar to the _flashes partial in Suspenders:

<div id="flash">
  <% flash.each do |key, value| -%>
    <div id="flash_<%= key -%>"><%= html_escape(value) %></div>
  <% end -%>

which is then rendered inside the body tag of your application layout:

<%= render :partial => ‘layouts/flashes’, :locals => { :flash => flash } -%>

Custom layout

If you need to use a custom layout in any of the clearance controllers, but do not want to override actual controllers, putting them into app/controllers directory you can add

Clearance::SessionsController.layout "custom_clearance_layout"

in your config file.