我想在我的自定义验证方法中调用活动记录验证方法
class Asset < ActiveRecord::Base
validate :ensure_unique_identification_code
validates :name,:uniqueness=>true
def ensure_unique_identification_code
self.identifier="identifier code" #code is generated using some helper method of Asset model
validates :identifier ,:uniqueness=>true
end
end
给出错误
undefined method `validates' for #<Asset:0xb6692dbc>
我们如何在模型的实例方法中调用验证方法
最佳答案 请检查此链接(它有答案):
How to call ActiveRecord validators as instance methods (ala Sequel)?