我想在使用包含验证时包含一个类方法作为我的选项:
class Search < ActiveRecord::Base
attribute :foo, Array
validates :foo, inclusion: class_method_options
def self.class_method_options
['foo', 'bar']
end
end
Run Code Online (Sandbox Code Playgroud)
但是我得到了undefined method 'class_method_options' for Search:Class (NoMethodError).
我尝试使用谷歌搜索解决方案,但刚刚找到了如何创建自定义验证.我不需要全新的验证,我只想使用标准的Rails包含验证器.如何class_method_options从包含验证中访问?