Validates inclusion of an attribute

suggest change

You can check if a value is included in an array using the inclusion: helper. The :in option and its alias, :within show the set of acceptable values.

class Country < ApplicationRecord
  validates :continent, inclusion: { in: %w(Africa Antartica Asia Australia
                                            Europe North America South America) }
end

To check if a value is not included in an array, use the exclusion: helper

class User < ApplicationRecord
  validates :name, exclusion: { in: %w(admin administrator owner) }
end

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


ActiveRecord validations:
*Validates inclusion of an attribute

Table Of Contents
11ActiveRecord validations
55CSV