laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Jan-29 19:34 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wildtangent
2008-Jan-29 21:30 UTC
Re: restful_authentication: redirecting if already logged in
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, "laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org" <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote:> 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. Visitinghttp://mydomain.com/register/startgives 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Jan-29 23:43 UTC
Re: restful_authentication: redirecting if already logged in
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 On Jan 29, 3:30 pm, Wildtangent <wildtang...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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, "laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org" > > > > <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote: > > 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. Visitinghttp://mydomain.com/register/startgivesthis 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- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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, "laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org" <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote:> 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 > > On Jan 29, 3:30 pm, Wildtangent <wildtang...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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, "laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org" > > > <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote: > > > 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. Visitinghttp://mydomain.com/register/startgivesthiserror: > > > > 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- Hide quoted text - > > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---