Weird bug in Devise path after sign in with /admins/sign_in rather than /admins

1k views Asked by At

Im using devise right now and im authenticating with admins and users (two separate types of login). Everything works fine if I go to .../admins and .../users. However, when I go to the url /admins/sign_in, after I sign in it auto redirects me back to the homepage instead of the /admins page like I want. Is there a way for me to redirect it after the /sign_in url?

2

There are 2 answers

4
thenengah On BEST ANSWER

In routes.rb make sure you include this named paths.

map.user_root '/users/edit', :controller => 'users', :action => "edit"
map.admin_root '/admin/edit', :controller => 'users', :action => "edit"

I do this so it redirects to the uses settings.

Update

I'm still on 2.3.8 so for rails 3 you will need to use this:

root :to => "home"

You can find it here: https://github.com/plataformatec/devise

Update

Actually the first code I posted should work for all versions of rails. And just listing root by itself is the default for all devise resources.

0
Braden Becker On

When you log in devise will run the method after_sign_in_path_for(resource_or_scope) to determine where to go, by default this method will look for an admin_root path and if that doesn't exist it will redirect users to the root path. Another option would be to over write this method. Please take a look at my answer to this question for more details.

For more information take a look at the devise documentation.