1. Computing

Rails Blog Tutorial - Adding RESTful Authentication

By

2 of 8

RESTful Authentication

The RESTful authentication plugin by Rick Olson (AKA technoweenie) provides user registration and authentication. The authenticated generator will generate a Users and Sessions controller, as well as a migration to create the database table for the users. RESTful authentication is a common way of implementing authentication in post Rails 1.2 projects. Earlier projects used a plugin called acts_as_authenticated (also by Rick Olson).

One change will be made to the typical mode of operation of RESTful authentication. Since we only want bloggers authorized on the site to be able to log in, the user registration controller will be deleted. To add new users to the database, the console will have to be used and, since adding or deleting bloggers is an infrequent task, this is a reasonably manageable solution.

To install RESTful authentication, first add technoweenie's plugin collection to your plugin sources. After that's done, install the plugin and run the generator.

$ script/plugin source http://svn.techno-weenie.net/projects/plugins
 Added 1 repositories.
 
 $ script/plugin install restful_authentication
 + ./README
 + ./Rakefile
 + ./generators/authenticated/USAGE
 + ./generators/authenticated/authenticated_generator.rb
 + ./generators/authenticated/templates/activation.html.erb
 + ./generators/authenticated/templates/authenticated_system.rb
 + ./generators/authenticated/templates/authenticated_test_helper.rb
 + ./generators/authenticated/templates/controller.rb
 ... snip ...
 
 $ script/generate authenticated user sessions
  1. About.com
  2. Computing
  3. Ruby
  4. Ruby on Rails
  5. RESTful Authentication

©2014 About.com. All rights reserved.