I am following the official getting started guide of Ruby on Rails. The guide provides the following code to add status validation to the concern:
module Visible
extend ActiveSupport::Concern
included do
VALID_STATUSES = ['public', 'private', 'archived']
validates :status, in: VALID_STATUSES
end
def archived?
status == 'archived'
end
end
However I get the following error: Unknown validator: 'InValidator'
on line validates :status, in: VALID_STATUSES
. I am using Rails 6.1.0 and following the guide for this version exactly. What is the problem here?
Edit
I have done a small change to make it work: validates :status, inclusion: { in: VALID_STATUSES }
. But I want to know why in
is not working as in the guide.
The guide seems to be wrong, your solution with changing it to inclusion: { in: [] }
is correct.
There is already a fix merged in the Rails repository but seems not yet deployed.
To add some background information how this works, the implementation in Rails does instantiate the validator class which is called InclusionValidator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With