restful_authentication: redirecting if already logged in

Hi,

If someone is already logged in, I would like to redirect them to a different page. I have that code in my app/controllers/ register_controller.rb file:

class RegisterController < ApplicationController ...         def start                 if (logged_in?)                         redirect_to :controller => "order", :action => "start"                 end         end ... end

but I'm getting an error if someone is not logged in. Visiting http://mydomain.com/register/start gives this error:

NoMethodError in RegisterController#start undefined method `authenticate_with_http_basic' for #<RegisterController:0xb75ed528> RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace

/usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:102:in `login_from_basic_auth' /usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:12:in `current_user'

/usr/local/apache2/htdocs/easyrx/lib/authenticated_system.rb:6:in `logged_in?' /usr/local/apache2/htdocs/easyrx/app/controllers/ register_controller.rb:40:in `start'

The method in question is located in lib/authenticated_system.rb, and I've included that in my app/controllers/application.rb file:

class ApplicationController < ActionController::Base   # Be sure to include AuthenticationSystem in Application Controller instead   include AuthenticatedSystem

What does the error mean and how can I resolve it? Thanks, - Dave

looks like you are not using rails 2. You'll need to be on rails 2 to use the current incarnation of restful_authentication, as it uses the new built in http authentication classes. Also, your whole controller structure doesn't look very RESTful! Start now and be happy later.

Once you find a version of REStful_authentication that works with Rails 1.2.x or update to Rails 2 see what the #create method does in the (default) sessions controller to see how best to use the logged_in? helper to check the login status, use RESTful or named routes to do your redirect! (you'll thank me later)

Joe

Hi,

According to my command prompt

[me@mymachine]~/% rails --version Rails 2.0.2

I'm using Rails 2. What else could it be? And please throw in any suggestions that would make my controller more RESTful.

Thanks, - Dave

Any chance you have multiple versions of rails and you're dealing with an older project that you started in 1.x? If that's the case then I'd check the rails version in environment.rb -- you may still be running your app on 1.x even with 2.x installed. (BTW, I get the same response with rails --version and i've got six versions of the framework installed).