【问题标题】:Rails redirecting to a subdomain with a notice messageRails 重定向到带有通知消息的子域
【发布时间】:2017-01-21 01:29:53
【问题描述】:

我正在根据参数将用户重定向到应用程序的子域

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

带有通知消息,我将用户重定向到的 html 页面看起来像

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

用于显示 Flash 消息。

但是这里的问题是没有显示通知消息。

是否使用子域导致此问题,因为如果删除子域并且如果我重定向到同一子域中的 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: { notice: "Couldn't able to process your request, please try after some time" }会怎样
  • @Andrey Deineko 是的,我也试过了,但没有显示消息。
  • 尝试用flash.each... 注释掉你的部分——看看默认行为是否有效。你的代码看起来不错
  • @AndreyDeineko 感谢您的回复。我也尝试过相同的方法,但无法显示消息。
  • @AndreyDeineko 我做了一些编辑,你能看看吗

标签: html ruby-on-rails subdomain


【解决方案1】:

Flash 消息存储在与 cookie 绑定的会话中。 (如果您使用 cookie_store,所有会话数据都保存在 cookie 中,或者如果您使用 active_record_session,则您有一个与数据库中的数据相关联的会话 cookie。

问题是 cookie 不会跨子域跟踪您,除非您已将它们配置为。见Share session (cookies) between subdomains in Rails?

听起来关键部分是在配置会话存储的行中包含domain: '.yourdomain.com'。来自Action Controller Overview: Sessions

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 2012-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多