Skip to content

Instantly share code, notes, and snippets.

@timurvafin
Created April 7, 2011 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timurvafin/907485 to your computer and use it in GitHub Desktop.
Save timurvafin/907485 to your computer and use it in GitHub Desktop.
class ActiveRecord::Base
validate do |record|
record.class.columns.select{|c| [:string, :text].include?(c.type) && c.limit.present? }.each do |column|
validator = ActiveModel::Validations::LengthValidator.new(:attributes => [column.name], :maximum => column.limit)
validator.validate(record)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment