Skip to content

Instantly share code, notes, and snippets.

@joice
Last active December 22, 2015 11:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joice/6463962 to your computer and use it in GitHub Desktop.
Save joice/6463962 to your computer and use it in GitHub Desktop.
Flash messages helper with filter before print them
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