1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Rails Blog Tutorial - Adding RESTful Authentication


3 of 8

Removing the Users Controller

The Users controller created by the RESTful authentication generator provides an interface with which users of the site can register and become authenticated users. Since this is your blog, we don't want this to happen--simply destroy the Users controller and delete the user views.

$ script/destroy controller users
rm app/helpers/user s_helper.rb
rm test/functional/ users_controller_test.rb
rm app/controllers/ users_controller.rb
notempty test/functional
notempty test
... snip ...
$ rm -Rf app/views/users

There's one final requirement before you can implement authentication in all of your controllers. In your application controller located at app/controllers/application.rb, you must include the AuthenticatedSystem module. If you don't do this, the required before filters and view helpers will not available in all controllers. You also must remove this included module from the Accounts controller. Since it's included in the application-wide controller, it will automatically be included in all other controllers and, thus, isn't needed there.

# File: app/controllers/application.rb
 class ApplicationController < ActionController::Base
   include AuthenticatedSystem
 ... snip ...
# File: app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
  # Comment out or delete the following line
  # include AuthenticatedSystem
 ... snip ...
  1. About.com
  2. Technology
  3. Ruby
  4. Ruby on Rails
  5. Removing the Users Controller

©2014 About.com. All rights reserved.