更改 Rails 服务器上的响应 URL



我正在尝试更改我的响应 URL 以重定向(不重定向(到自定义子域。我正在使用deviseapartment,并且在成功请求后尝试使用用户的子域。

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 应用程序上,我可以访问 devise 的current_user

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

最新更新