我希望跨域名(而不是子域名)使用会话。例如,我有.co.uk、.com.au和.com三个域名,它们都指向同一个地址。
对于子域名,我知道可以使用以下方法:
SomeApp::Application.config.session_store :cookie_store, key: '_some_app_session', domain => :all, :tld_length => 2
但我希望我的解决方案能够在不同的域之间运行,以便拥有一个共享的会话/cookie 集合。
我希望跨域名(而不是子域名)使用会话。例如,我有.co.uk、.com.au和.com三个域名,它们都指向同一个地址。
对于子域名,我知道可以使用以下方法:
SomeApp::Application.config.session_store :cookie_store, key: '_some_app_session', domain => :all, :tld_length => 2
但我希望我的解决方案能够在不同的域之间运行,以便拥有一个共享的会话/cookie 集合。
before_filter :redirect_to_dot_com
...
def redirect_to_dot_com
url = "http://example.com" + request.fullpath
url= destination + (url.include?('?') ? '&' : '?') + "token=#{current_user.token}" if signed_in?
redirect_to url, status: 301
end
如果你已经使用会话,我不会使用通过:get
传递?php=bad
风格变量的PHP样式路由,因为这样做需要解析原始URL和大量其他工作。
相反,你可以使用session[:edition_id] = 'UK'
代替:
cookies[:edition_id] = { value: 'UK', domain: 'some-app.com', expires: 1.year.from_now }
# or if you want to be google 10.years.from_now
session[:edition_id] = 'UK'
时,该值将由rails加密并存储在_myapp_session cookie中。但在您的情况下,这可能并不重要。