Skip to content

Instantly share code, notes, and snippets.

@alpaca-tc
Created May 23, 2021 13:17
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
値がtrue/falseのいずれかであることをテスト
# validates :column_name, boolean: true のように使う
class BooleanValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.is_a?(TrueClass) || value.is_a?(FalseClass)
record.errors.add(attribute, :not_boolean)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment