Created
October 2, 2014 21:38
-
-
Save twohlix/9532f3b7b77b73c9bb79 to your computer and use it in GitHub Desktop.
Add Errors Once
This file contains 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
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