在Rails服务器上更改响应URL

问题描述:

我在尝试将我的响应URL更改为重定向(不重定向)到自定义子域。我正在使用deviseapartment,我试图在成功请求后使用用户的子域名。在Rails服务器上更改响应URL

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 

我想请求被发送到lvh.me(域名为本地主机)被重定向到tenant_name.lvh.me。此外,我想避免在中间件中做这件事(但如果有办法做到这一点,请让我知道),因为在rails应用程序中,我可以访问设计的current_user

我不太明白你的问题,但这是你在找什么? redirect_to some_path(subdomain: false) #redirect to localhost or whatever the host is without subdomain and redirect_to some_path(subdomain: tenant_subdomain_from_a_variable) #redirects to provided subdomain