Skip to content

Instantly share code, notes, and snippets.

@twohlix
Created October 2, 2014 21:38
Show Gist options
  • Save twohlix/9532f3b7b77b73c9bb79 to your computer and use it in GitHub Desktop.
Save twohlix/9532f3b7b77b73c9bb79 to your computer and use it in GitHub Desktop.
Add Errors Once
message = 'This is some error message'
errors.add(:attribute, message) unless errors.added?(:attribute, message)
# or should we create an add_once on errors. Can be done as a monkey patch but a core contribution would be better
def ActiveRecord::Errors
def add_once(attribute, message)
add(attribute, message) unless added?(attribute, message)
end
end
errors.add_once(:attribute, 'this is some error message')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment