Last active
December 22, 2015 11:09
-
-
Save joice/6463962 to your computer and use it in GitHub Desktop.
Flash messages helper with filter before print them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FlashMessagesHelper | |
def flash_messages | |
safe_buffer do |html| | |
filtered_flash_messages.each do |name, message| | |
html << content_tag(:div, content_tag(:p, message), :class => "message #{name}") | |
end | |
end | |
end | |
private | |
def safe_buffer(&block) | |
buffer = ActiveSupport::SafeBuffer.new | |
yield buffer if block_given? | |
buffer.html_safe | |
end | |
def filtered_flash_messages | |
[:timedout].each do |type| | |
flash.discard(type) | |
end | |
flash | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment