简体   繁体   English

Rails重定向到带有通知消息的子域

[英]Rails redirecting to a subdomain with a notice message

I am redirecting the user to a subdomain of the application based on the parameter 我正在根据参数将用户重定向到应用程序的子域

respond_to do |format|
      format.html {  redirect_to home_url(subdomain: params[:company]), notice: "Couldn't able to process your request, please try after some time" }
end

with a notice message, and the html page to which i am redirecting the user looks like 带有通知消息,并且我将用户重定向到的html页面看起来像

<% flash.each do |name, msg| %>
    <%= content_tag :div, msg, class: "alerts alerts-info bodyLeftPadd" %>
<% end %>

for displaying the flash message. 用于显示即时消息。

But the problem here is the notice message is not displayed. 但是这里的问题是未显示通知消息。

Is the use of subdomain causing this problem, because if remove the subdomain and if i redirect to the url within the same subdomain i could see the flash message being displayed. 使用子域是否会导致此问题,因为如果删除子域,并且如果我重定向到同一子域中的url,我可能会看到显示的Flash消息。

 respond_to do |format|
          format.html {  redirect_to home_url, notice: "Couldn't able to process your request, please try after some time" }
 end

Flash messages are stored in your session, which is tied to a cookie. Flash消息存储在与Cookie关联的会话中。 (If you're using cookie_store all session data is kept in the cookie, or if you're using active_record_session you have a session cookie which is tied to data in your database). (如果您使用cookie_store所有会话数据都保留在cookie中,或者如果您使用active_record_session您将拥有一个会话cookie,该会话cookie与数据库中的数据相关联)。

The problem is that cookies won't follow you across subdomains unless you've configured them to. 问题在于,除非您已配置Cookie,否则Cookie不会跨子域跟随您。 See Share session (cookies) between subdomains in Rails? 请参阅在Rails的子域之间共享会话(cookie)?

It sounds like the critical part is to include domain: '.yourdomain.com' in the line where you configure your session store. 听起来关键部分是在配置会话存储的行中包含domain: '.yourdomain.com' From Action Controller Overview: Sessions : 动作控制器概述:会话

Rails.application.config.session_store :cookie_store, key: '_your_app_session', domain: ".example.com"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM