Ruby on rails 设计在其他页面显示flash消息

Ruby on rails 设计在其他页面显示flash消息,ruby-on-rails,devise,flash-message,Ruby On Rails,Devise,Flash Message,在我登录之后,如果我进入/users/edit页面,我会收到一条闪光消息 您已成功登录 在注册控制器中,我尝试了: flash.now # either this or below one flash.discard 我也试过这样的布局 <% if flash[:alert] || flash[:error] || flash[:notice] %> <%= content_tag :div, :class => "alert alert-inf

在我登录之后,如果我进入/users/edit页面,我会收到一条闪光消息 您已成功登录

在注册控制器中,我尝试了:

flash.now  # either this or below one
flash.discard
我也试过这样的布局

    <% if flash[:alert] || flash[:error] || flash[:notice] %>
       <%= content_tag :div, :class => "alert alert-info info-inside" do -%>
          <button class="close" data-dismiss="alert">×</button>
          <%= flash.now[:alert] if flash[:alert] %>
          <%= flash.now[:error] if flash[:error] %>
          <%= flash.now[:notice] if flash[:notice] %>
       <% end -%>
    <% end %>
另外,如果我创建产品并进入其他页面,它会显示错误的flash消息。刷新时它会消失


请告诉我如何避免此类即时消息。我在布局文件和需要的控制器中尝试了flash.now和flash.discard。但是它对我没有帮助。

请尝试下面的代码。它检查flash消息是否确实存在,然后获取成功消息和错误消息

<% if flash.present? %>
<div id="flash" class="flash">
<% flash.each do |name, msg| %>
  <div class="alert alert-<%= name == :notice ? "success" : "error" %>">
    <%= content_tag :div, msg, id: "flash_#{name}" if msg.is_a?(String) %>
  </div>
<% end %>

我知道这张票很旧,但是,你解决了这个问题吗?如果是,你介意分享吗?