に依存するアプリケーションを入手しましたCouchbase::Model
。すべての厄介なデータベース ハッキングをカプセル化するクラスを作成し、特定の属性を独自の方法で検証する必要があります。そこで、カスタム検証メソッドを作成しました:
class AdServeModel < Couchbase::Model
validate :validate_attributes
[...] (some other stuff happens here)
def validate_attributes
#First we validate the objects we belong_to
unless belongsToModels.nil?
belongsToModels.each do |attribute|
retrievedClass = attribute.to_s.camelize.constantize.find(
send("#{belongsToAttributeName(attrName)}"))
errors.add(attribute.to_sym, "#{attribute} is invalid") unless !retrievedClass.nil? and retrievedClass.valid?
end
end
end
しかし、これを実行しようとすると、次のようになります
undefined method 'validate' for AdServeModel(id):Class (NoMethodError)
。私はかなり困惑しています。なぜこれが起こるのかについての指針をいただければ幸いです。さらにコードが必要な場合は、コメントでそのように言ってください。