Created
May 11, 2011 22:33
-
-
Save virtualstaticvoid/967534 to your computer and use it in GitHub Desktop.
Flash Messages Helper
This file contains hidden or 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
| # 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