Search code examples
authenticationruby-on-rails-pluginsdevise

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


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?


Solution

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