2013-03-29 33 views
1

我登錄後,然後如果我去/用戶/編輯頁面我得到的Flash消息 「您已成功登錄」。設計顯示其他頁面中的Flash消息

在註冊控制器我想:

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 %> 

另外,如果我創造產品並得到了其他頁面它顯示了錯誤的閃存messages.On刷新它去遠。

請告訴我如何避免這種Flash消息。我在我的佈局文件中以及需要的控制器中嘗試了flash.now和flash.discard。但它並沒有幫助我。

回答

0

請嘗試下面的代碼。它會檢查閃存消息是否實際存在,然後獲取成功的消息和錯誤消息。

<% 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 %>