Setting up Restful Authentication

RESTful Authentication replaces the Acts as Authenticated plugin. Both plugins are by technoweenie, but he has stopped development on the latter.

  1. To install restful_authentication:
  2. Once installed, run ./script/generate authenticated user sessions --include-activation
    • We add --include-activation so that users are emailed after activation.
  3. Add the following line inside the Rails::Initializer.run do |config| block of config/environment.rb
    config.active_record.observers = :user_observer
  • Change sessions_controller.rb:
      # render new.rhtml
      def new
        # Store the referer so that we can go back to where the user wanted to log in.
        referer = URI::parse(request.referer)
        session[:return_to] = referer.path if referer.host == request.host
      end