Skip to content

Instantly share code, notes, and snippets.

@fuJiin
Created November 9, 2011 01:56
Show Gist options
  • Select an option

  • Save fuJiin/1350077 to your computer and use it in GitHub Desktop.

Select an option

Save fuJiin/1350077 to your computer and use it in GitHub Desktop.
flash_from_errors
# 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