mar*_*ini 1 subdomain ruby-on-rails localhost devise apartment-gem
我在设计登录或退出后重定向到子域时遇到问题。我生成了设计控制器未注释的方法,这些方法应该带我去我想要的地方,但子域不起作用。
def after_sign_in_path_for(resource)
root_url(subdomain: resource.subdomain)
end
def after_sign_out_path_for(resource_or_scope)
home_url(subdomain: "www")
end
Run Code Online (Sandbox Code Playgroud)
登录后我收到错误
不安全的重定向到“http://chris.lvh.me:3000/”,无论如何都要传递allow_other_host: true来重定向。
因此,我以几种方式修改了方法,但它给了我更多错误,我尝试过的示例:
root_url(subdomain: resource.subdomain), allow_other_hosts: true
root_url(subdomain: resource.subdomain, allow_other_hosts: true)
redirect_to root_url(subdomain: resource.subdomain),allow_other_hosts: true
redirect_to root_url(subdomain: resource.subdomain, allow_other_hosts: true)
Run Code Online (Sandbox Code Playgroud)
错误是:参数数量错误或意外的“、”预期结束或其他内容。
退出后,我会进入登录页面,而不是 home_url,并且子域不会更改。
我正在使用 devise、rails-on-services/apartment 和 Rails 7
方法名称为allow_other_host,不带s.
除此之外,你应该将它作为参数传递给redirect_to
redirect_to(root_url, allow_other_host: true)
Run Code Online (Sandbox Code Playgroud)
该方法request.subdomain将使用当前 URL 来确定子域。如果您想重定向到与当前 URL 不同的子域,则可以指定它。
redirect_to(root_url(subdomain: "chris", allow_other_host: true)
# "http://chris.lvh.me:3000/"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2527 次 |
| 最近记录: |