module

ActiveRecord::Validations::ClassMethods

No documentation available for this module.

Files

  • activerecord/lib/active_record/validations.rb
  • activerecord/lib/active_record/validations/associated.rb
  • activerecord/lib/active_record/validations/uniqueness.rb

1Note

Conditions work for lower-level validate methods too

mcmire ยท Jun 12, 20091 thank

I don't think this is mentioned in the docs anywhere, or else I couldn't find it: Because validate, validate_on_create, and validate_on_update are ActiveSupport::Callbacks, their symbol forms support conditions just like validates_presence_of and company:

validate :permaname_must_be_unique, :if => :normal_entry?
validate_on_create :posted_at_must_be_valid_timestamp, :unless => Proc.new {|e| e.posted_at.nil? }
validate_on_update :title_must_not_contain_apostrophes, :if => :title_starts_with_a_b?