Need Urgent Help - Devise + Subdomain - Redirect user for sign_in

794 views
Skip to first unread message

firoz

unread,
Dec 21, 2011, 12:25:58 AM12/21/11
to Devise
I am using devise gem in a rails application with multiple subdomains.
Each subdomain is handled by respective controller, which look like
this:

class Subdomain1Controller < ApplicationController
before_filter :authenticate_user!
def index
end
end

With above controller implementation, Devise always keep subdomain
while redirecting user to login page. In above case, Devise redirect
user to http://subdomain1.acmesite/users/sign_in instead of a common
sign_in Url.

This leads to having multiple sign_in urls for each sub-domains.

http://subdomain1.acmesite/users/sign_in
http://subdomain2.acmesite/users/sign_in
http://subdomain3.acmesite/users/sign_in

I am wondering if it's possible to override devise method to exclude
subdomain part from the url and yet keeping the previous page url
information. More preciously, I wants Devise to redirect user to a
specific Url (like: http://acmesite/users/sign_in) irrespective of
subdomain and after successful authentication, Devise should return
user back to the caller subdomain+page.

Carlos Antonio da Silva

unread,
Dec 28, 2011, 10:11:43 AM12/28/11
to plataforma...@googlegroups.com
Devise uses the path to redirect, so Rails keeps the host/subdomain as it is. To do that, you will have to override the  failure app so when someone tries to access a page that should required a signed in user, it is redirected correctly:


This wiki can help you (but you'll probably need to override the redirect_url method only): https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated
--
At.
Carlos Antonio
Reply all
Reply to author
Forward
0 new messages