I am trying to change my response URL to redirect (without redirect) to custom subdomain. I am using devise
and apartment
and I am trying to use User's subdomain after successful request.
before_action :authenticate_user!
after_action :switch_tenant_response
def switch_tenant_response
response.headers["SERVER_NAME"] = 'tenant_name.lvh.me' # does not work
end
I would like to request being sent to lvh.me
(domain name for localhost) be redirected to tenant_name.lvh.me
. Also I would like to avoid doing this in middleware (but if there is a way to do it please let me know) since on rails app I have access to devise's current_user
.
I don't quite get your question, but is this what you're looking for?
redirect_to some_path(subdomain: false) #redirect to localhost or whatever the host is without subdomain
andredirect_to some_path(subdomain: tenant_subdomain_from_a_variable) #redirects to provided subdomain