Included module validations not seeing delegated instance methods

Hi,

Maybe the form of my validations module is deficient…

module MyValidationsModule
extend ActiveSupport::Concern

included do
validate :some_custom_validation
end

def some_custom_validation
<references to various instance methods of parent, e.g., ref_1 &
ref_2, here>
end
end

…because when I include this module in a parent class and then in
that parent delegate to the methods of an associated AR class…

delegate :ref_1, :ref_2, :prefix=>false, :to=>:associated_ar

…when the validations execute in the parent, they do not find the
delegated instance methods.

Any thoughts?

Thanks,

Lille

On Friday, May 13, 2011 6:10:19 AM UTC-6, Lille wrote:

end

def some_custom_validation
<references to various instance methods of parent, e.g., ref_1 &
ref_2, here>
end
end

Wow, getting fancy there. Just a little off topic question, any reason
why
you don’t want to use the ActiveModel::Validator module and the
#validates_with helper to break-out/organize your custom validations?

http://guides.rubyonrails.org/active_record_validations_callbacks.html#validates_with

Sure, just a few questions. If you manually define your methods #ref_1
and
#ref_2 (and just put logging code in their implementations) as opposed
to
using delegation methods, do they get called? Also, what is the exact
error
message or indication of failure? Can you provide any more code? Are the
delegations to a class where the parent (that includes your validation
module) has_many, has_one, or belongs_to the associated model?