Created
January 7, 2010 14:47
-
-
Save dreamr/271259 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
ActiveRecord::Base.class_eval do | |
def self.validates_inlcusion_of(*attr_names) | |
configuration = { :minumum => 1 } | |
configuration.update(attr_names.extract_options!) | |
validates_each(attr_names, configuration) do |record, attr_name, value| | |
unless value.nil? | |
record.errors.add(attr_name, "must contain at least #{configuration[:minimum]}") if value.size < configuration[:minimum].to_i | |
end | |
end | |
end | |
end |
This file contains hidden or 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 SomeModel < ActiveRecord::Base | |
validates_inlcusion_of :choices, :minimum => 2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment