Skip to content

Instantly share code, notes, and snippets.

@lesniakania
Created February 26, 2015 09:01
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 lesniakania/bfd6b65f661bced7b394 to your computer and use it in GitHub Desktop.
Save lesniakania/bfd6b65f661bced7b394 to your computer and use it in GitHub Desktop.
class BaseValidator
include ActiveModel::Validations
def initialize(record_params = {})
self.class.fields.each do |field|
val = record_params[field]
send("#{field}=", val)
end
end
end
class NameValidator < BaseValidator
def self.fields
[:name]
end
attr_accessor(*fields)
validates :name, presence: true
validates :name, length: { maximum: A9n.validations[:max_text_field_size] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment