Skip to content

Instantly share code, notes, and snippets.

@AJFaraday
Created April 26, 2011 15:30
Show Gist options
  • Save AJFaraday/942489 to your computer and use it in GitHub Desktop.
Save AJFaraday/942489 to your computer and use it in GitHub Desktop.
troublesome validation
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