1) You can create a custom validator class, which involves inheirting from ActiveModel::Validator and implementing a validate method that takes the records to validate:
class Report > ActiveRecord::Base
validates with MyValidator
end
class MyValidator < ActiveModel::Validator
def validate(record)
record.errors[:base] = << "Error" unless is_valid(record)
end
end
2) In rails 3, there are validation macros as wel, which means extending ActiveModel::EachValidator:
class Report < ActiveRecord::Base
validates :name :report_like => true
end
class ReportLikeValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value["Report"]
record.errors.add attribute, "Does not appear to be a ..."
end
end