Skip to content

Instantly share code, notes, and snippets.

@virtualstaticvoid
Created May 11, 2011 22:33
Show Gist options
  • Select an option

  • Save virtualstaticvoid/967534 to your computer and use it in GitHub Desktop.

Select an option

Save virtualstaticvoid/967534 to your computer and use it in GitHub Desktop.
Flash Messages Helper
# http://rubypond.com/blog/useful-flash-messages-in-rails
FLASH_NOTICE_KEYS = [:error, :notice, :warning]
def flash_messages
return unless messages = flash.keys.select{|k| FLASH_NOTICE_KEYS.include?(k)}
formatted_messages = messages.map do |type|
content_tag :div, :class => type.to_s do
message_for_item(flash[type], flash["#{type}_item".to_sym])
end
end
formatted_messages.join
end
def message_for_item(message, item = nil)
if item.is_a?(Array)
message % link_to(*item)
else
message % item
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment