class A
include ActiveModel::Validations
attr_reader :operator
def initialize(operator)
@operator = operator
validates_inclusion_of :operator, in => operators
end
def operators
....
end
end
Here I want to validate the operator for inclusion_of dynamically. the method operators returns an array of operators which is dynamic.
The above code is not working. How can I implement the validation dynamically?
r
You may try:
although I don’t understand why can’t you just define it at the class level. Note that argument to :in can be a lambda, for details refer to: http://apidock.com/rails/ActiveModel/Validations/HelperMethods/validates_inclusion_of