Created
November 9, 2011 01:56
-
-
Save fuJiin/1350077 to your computer and use it in GitHub Desktop.
flash_from_errors
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
| # first option should specify the flash type. | |
| # defaults to :error if not given | |
| def flash_from_errors(object, *options) | |
| type = ([:notice, :error, :alert, :success, :news] & options)[0] || :error | |
| msg = object.errors.full_messages.join(", and ").downcase.capitalize | |
| options.include?(:now) ? flash.now[type] = msg : flash[type] = msg | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment