3

On my local machine, when I authenticate at http://subdomain.myapp.dev (using the Pow server), I am properly redirected to the index page.

When logging into the production domain http://subdomain.myapp.com (hosted on Heroku), I am also able to properly authenticate; however, Heroku is not redirecting to the index page. After submitting the necessary credentials, I receive the 'Signed in successfully' notification but remain on the sign in page.

rake routes and heroku run rake routes return identical routing schemes. I've also listed the contents of my routes.rb file below

Example::Application.routes.draw do  

  devise_scope :user do
    authenticated :user do
      root :to => 'admin/servers#index'
    end

    unauthenticated :user do
      root :to => 'devise/sessions#new'
    end
  end

  resources :server_imports
  resources :servers

  devise_for :users

  ActiveAdmin.routes(self)
end

Below are the logs after entering the credentials for signing in:

2013-10-12T01:59:32.110046+00:00 app[web.1]: Started POST "/users/sign_in" 
2013-10-12T01:59:32.529842+00:00 app[web.1]: Started GET "/"

And here is the first line from heroku run rake routes

root GET    /     admin/servers#index

As mentioned above, I still get re-routed to the sign in page after successful authentication. I am confused why this problem is only experienced on Heroku and not on my local machine

Anconia
  • 3,888
  • 6
  • 36
  • 65
  • This totally messed my brain up, because everything I thought of was covered. There are 2 things it might be -- You might need to put devise_for :users above the devise_scope, and ActiveAdmin may work differently on Heroku? – Richard Peck Oct 12 '13 at 17:01
  • @RichPeck Unfortunately moving `devise_for :users` above the devise_scope did not resolve the issue – Anconia Oct 13 '13 at 03:37
  • @Anconia is the redirection after login the problem or are you not able to login at all? the last case might be due to cookie problems, especially if you do some ssl stuff. – phoet Oct 13 '13 at 18:18
  • @phoet I can login to the application; the redirection after login is the issue – Anconia Oct 13 '13 at 18:40
  • 1
    @Anconia : Try devise routes at my answer [here](http://stackoverflow.com/a/19242506/1297435), let me know what happens after try that. – rails_id Oct 15 '13 at 01:18
  • @anonymousxxx that worked! I had to alter my application controller as you mentioned, as well as reconfigure my routes. Thank you so much! – Anconia Oct 19 '13 at 03:36

1 Answers1

2

Why not do something like this:

def after_sign_in_path_for(resource)
    admin_servers_index_path
end

See: https://github.com/plataformatec/devise/wiki/How-To%3A-Redirect-to-a-specific-page-on-successful-sign-in-and-sign-out

CDub
  • 13,146
  • 4
  • 51
  • 68
  • As I mentioned, I get routed correctly after I login on the dev server; which makes me skeptical to change the `after_sign_in_path` method. – Anconia Oct 17 '13 at 01:53