2011-02-02 70 views
0

我在application_helper.rb中使用這種方法來顯示flash。但是,我需要它來顯示閃光燈的內容和使閃光燈消失的鏈接,而我似乎無法做到這一點。它現在所做的只是顯示一個「關閉」鏈接。在rails上嵌套content_tag的幫助3

def show_flash 
     [:notice, :error, :alert].collect do |key| 
     content_tag(:div, (flash[key] and content_tag(:a, "close", :class => "#{key}", :href => "#", :onclick => "$('messages').fade(); return false;")), :id => key, :class => "flash_#{key}") unless flash[key].blank? 
     end.join 
    end 

回答

0

這是我想出的解決方案。這不是最好的,因爲它將整個閃光消息包裝在一個<a>標籤中,但它運行得很好。

def show_flash 
     [:notice, :errors, :alert].collect do |key| 
     msg = (flash[key].to_s + " (click to close)") 
     content_tag(:div, (content_tag(:a, msg, :class => "#{key}", :href => "#", :onclick => "$('messages').fade(); return false;")), :id => key, :class => "flash_#{key}") unless flash[key].blank? 
     end.join 
    end