Created
April 23, 2009 17:27
-
-
Save jmazzi/100619 to your computer and use it in GitHub Desktop.
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 Foo < ActiveRecord::Base | |
# attrs: bar (integer), baz (integer) | |
# want to make sure Foo.baz is > than Foo.bar | |
# this would only run validation when baz is numeric (because any int is > nil) | |
validates_each :bar do |record, attr, value| | |
if record.baz.is_a?(Numeric) | |
if value.is_a?(Numeric) | |
record.errors.add attr, 'must be less than baz.' unless value < record.baz | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment