Created
April 26, 2011 15:30
-
-
Save AJFaraday/942489 to your computer and use it in GitHub Desktop.
troublesome validation
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
class Pledge < ActiveRecord::Base | |
validates_presence_of :amount | |
def validate_positivity_of(*attr_names) | |
configuration = { :message => "Cannot be negative" } | |
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash) | |
validates_each attr_names do |m, a, v| m.errors.add(a, configuration[:message]) if v<=0 end | |
end | |
validate_positivity_of :amount | |
Results in | |
undefined method `validate_positivity_of' for #<Class:0xb571d184> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment