public
Description: Rails authentication with email & password.
Homepage: http://thoughtbot.com
Clone URL: git://github.com/thoughtbot/clearance.git
commit  8c149f1968f3d00aa4d22caec23fc74ad574af81
tree    aad7c2be35ba524dcee6014a2c089071ad4bfb2e
parent  442a0dd1528a5f362d6448e2c4723d7cc3988895
name age message
file .gitignore Tue Aug 04 12:48:45 -0700 2009 added clearance_views generator. by default, cr... [dancroak]
file CHANGELOG.textile Loading commit data...
file LICENSE Tue Nov 04 08:33:14 -0800 2008 Add license [mike-burns]
file README.textile
file Rakefile Wed Oct 21 07:53:50 -0700 2009 Release 0.8.3 [Joe Ferris]
file TODO.textile Mon Mar 30 06:40:37 -0700 2009 updating todo list [dancroak]
directory app/ Mon Aug 31 14:00:19 -0700 2009 Removed unnecessary remember_token_expires_at c... [Daniel Croak]
file clearance.gemspec Wed Oct 21 07:53:50 -0700 2009 Release 0.8.3 [Joe Ferris]
directory config/ Sat Jun 13 17:08:54 -0700 2009 adding sign_up, sign_in, sign_out named routes [dancroak]
file cucumber.yml Wed Oct 21 07:46:01 -0700 2009 Updated for Cucumber 0.4 [Joe Ferris]
directory generators/ Wed Nov 04 08:21:52 -0800 2009 [#48] unnecessary require 'factory_girl' in gen... [dancroak]
directory lib/ Wed Oct 21 07:50:53 -0700 2009 Fix for potential remember me token collisions [Joe Ferris]
directory rails/ Sat Sep 06 13:51:36 -0700 2008 Added test stuff. [technicalpickles]
directory shoulda_macros/ Tue Sep 01 08:12:52 -0700 2009 current_user= accessor method. call it on sign_... [Daniel Croak]
directory test/ Wed Nov 04 08:21:52 -0800 2009 [#48] unnecessary require 'factory_girl' in gen... [dancroak]
README.textile

Clearance

Rails authentication with email & password.

We have clearance, Clarence.

Suspenders

Clearance is included in Suspenders, which thoughtbot uses on all of our apps. We highly recommend you try it. Suspenders is the “King Gem” in our ecosystem, representing what we think the current state-of-the-art is in Rails development.

Installation

Clearance is a Rails engine. It works with versions of Rails greater than 2.3.

In config/environment.rb:

config.gem "thoughtbot-clearance",
  :lib     => 'clearance',
  :source  => 'http://gemcutter.org',
  :version => '0.8.3'

Vendor the gem:

rake gems:install
rake gems:unpack

Make sure the development database exists and run the generator:

script/generate clearance

A number of files will be created and instructions will be printed.

You may already have some of these files. Don’t worry. You’ll be asked if you want to overwrite them.

Run the migration:

rake db:migrate

If you aren’t on Suspenders, you aren’t done

Define a HOST constant in your environment files.
In config/environments/test.rb and config/environments/development.rb it can be:

HOST = "localhost"

In production.rb it must be the actual host your application is deployed to.
The constant is used by mailers to generate URLs in emails.

In config/environment.rb:

DO_NOT_REPLY = "donotreply@example.com"

Define root_url to something in your config/routes.rb:

map.root :controller => 'home'

Cucumber Features

As your app evolves, you want to know that authentication still works. thoughtbot’s opinion is that you should test its integration with your app using Cucumber.

Run the Cucumber generator (if you haven’t already) and Clearance’s feature generator:

script/generate cucumber
script/generate clearance_features

All of the files generated should be new with the exception of the features/support/paths.rb file. If you have not modified your paths.rb then you will be okay to replace it with this one. If you need to keep your paths.rb file then add these locations in your paths.rb manually:

def path_to(page_name)
  case page_name
   ...
  when /the sign up page/i
   new_user_path
  when /the sign in page/i
   new_session_path
  when /the password reset request page/i
   new_password_path
  ...
end

Formtastic views

We have begun standardizing our forms using Formtastic. We highly recommend trying it. It will make your Rails view life more interesting.

Clearance has another generator to generate Formastic views:

script/generate clearance_views

Its implementation is designed so that other view styles can be generated if the community wants it. However, we haven’t needed them so you’ll have to write the patch and send it back if you want other styles (such as Haml).

Authors

Clearance was extracted out of Hoptoad. We merged the authentication code from two of thoughtbot’s clients’ Rails apps and have since used it each time we need authentication. The following people have improved the library. Thank you!

Dan Croak, Mike Burns, Jason Morrison, Joe Ferris, Eugene Bolshakov, Nick Quaranto, Josh Nichols, Mike Breen, Marcel Görner, Bence Nagy, Ben Mabey, Eloy Duran, Tim Pope, Mihai Anca, Mark Cornick, Shay Arnett, Joshua Clayton, Mustafa Ekim, Jon Yurek, & Anuj Dutta.

Questions?

Ask the mailing list

Suggestions, Bugs, Refactoring?

Fork away and create a Github Issue. Please don’t send pull requests.