Override for after_sign_in_path_for() doesn't work

1,864 views
Skip to first unread message

Alex Le

unread,
Jun 2, 2010, 6:41:04 PM6/2/10
to Devise
Hi all,

I'm on Rails 3b3 and Devise 1.1.rc1. I'm trying to override the
"after_sign_in_path_for" method and it seems like the overriden method
is never called.

My setup is

devise_for :users , :controllers => { :sessions => "sessions" }

namespace :app do
root :to => "home#index"

end

I have tried to define after_sign_in_path_for in both the
SessionsController and ApplicationController, and put the debugger
breakpoints inside the method but the debugger never got triggered.

Anybody has any idea? I don't want to spam the Github bug report
before asking the mailing list, so any hint is appreciated.

Regards,

Alex

Carlos A. da Silva

unread,
Jun 2, 2010, 9:50:59 PM6/2/10
to Devise
Chances are you're being redirected to some location stored before you
sign in.
When you try to access some page that needs a signed in user, Devise
stores this page and redirects you to the sign in. After you sign in
successfully, it redirects you back to that page you were trying to
access.

Take a look at stored_location_for method, It's called always by
Devise in this case.

--
Carlos Antonio

SteveCaney

unread,
Jul 4, 2010, 9:49:31 AM7/4/10
to Devise
Hi there,
I'm having a similar issue:- when I remove my root
root :to => "admin#show"
redirection works as expected, and I can specify alternative hooks in
my overridden 'after_sign_in_path_for' but I don't want to remove the
root, is there any way I can bypass stored_location_for in my
after_sign_in_path_for?

Regards
Steve

On Jun 3, 2:50 am, "Carlos A. da Silva"

Carlos A. da Silva

unread,
Jul 4, 2010, 10:22:59 AM7/4/10
to Devise
Just implement this method in your application controller, returning
nil, then you bypass stored location.
Remember that by doing this, if your user access a url that needs to
be authenticated, then he/she authenticates, the application won´t
redirect the user to that url he/she attempted to access, but will
redirect to your root path (or wathever path you point in
after_sign_in_path_for).

--
Carlos Antonio
Reply all
Reply to author
Forward
0 new messages