Skip to content

Instantly share code, notes, and snippets.

@dreamr
Created January 7, 2010 14:47
Show Gist options
  • Save dreamr/271259 to your computer and use it in GitHub Desktop.
Save dreamr/271259 to your computer and use it in GitHub Desktop.
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
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