Irio Musskopf Junior
2012-Nov-04 02:41 UTC
Keep all validations inside a single ActiveModel::Validator class
Hi! I plan to use ActiveModel::Validator to validate a plain Ruby class, but I have intention to keep all validations outside the original class, while using PresenceValidator and FormatValidator, default on Rails. Something like this: # payer.rb module MyMoip class Payer include ActiveModel::Validations attr_accessor :id, :name, :email, :address_street, :address_street_number, :address_street_extra, :address_neighbourhood, :address_city, :address_state, :address_country, :address_cep, :address_phone validates_with Validators::PayerValidator end end # payer_validator.rb module MyMoip module Validators class PayerValidator < ActiveModel::Validator validate :id, presence: true def validate(record) # more complex validations end end end end It is possible? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.