Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown validator: 'InValidator' on Ruby on Rails

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.

like image 443
Shafquat Avatar asked Dec 19 '20 20:12

Shafquat


1 Answers

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.

like image 163
Christian Bruckmayer Avatar answered Nov 10 '22 10:11

Christian Bruckmayer