# Restful\_authentication: redirecting if already logged in

**URL:** <https://www.ruby-forum.com/t/restful-authentication-redirecting-if-already-logged-in/127494>\
**Category:** Rails\
**Created:** [January 29, 2008, 8:34pm UTC](https://www.ruby-forum.com/t/restful-authentication-redirecting-if-already-logged-in/127494 "2008-01-29T20:34:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 29, 2008, 8:34pm UTC](https://www.ruby-forum.com/t/restful-authentication-redirecting-if-already-logged-in/127494/1 "2008-01-29T20:34:42Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 29, 2008, 10:31pm UTC](https://www.ruby-forum.com/t/restful-authentication-redirecting-if-already-logged-in/127494/2 "2008-01-29T22:31:30Z")

</div>

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

On Jan 29, 7:34 pm, “removed\_email\_address@domain.invalid”

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 30, 2008, 7:28pm UTC](https://www.ruby-forum.com/t/restful-authentication-redirecting-if-already-logged-in/127494/3 "2008-01-30T19:28:16Z")

</div>

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).

On Jan 29, 6:43 pm, “removed\_email\_address@domain.invalid”

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 30, 2008, 12:44am UTC](https://www.ruby-forum.com/t/restful-authentication-redirecting-if-already-logged-in/127494/4 "2008-01-30T00:44:36Z")

</div>

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
