I would like to include a class method as my options when using the inclusion validation:
class Search < ActiveRecord::Base
attribute :foo, Array
validates :foo, inclusion: class_method_options
def self.class_method_options
['foo', 'bar']
end
end
However I get undefined method 'class_method_options' for Search:Class (NoMethodError)
.
I tried Googling for the solution, but just found how to create a custom validation. I don't need a whole new validation, I just want to use the standard Rails inclusion validator. How can I access class_method_options
from the inclusion validation?