Created
May 23, 2021 13:17
-
-
Save alpaca-tc/aa691507766dfde2474a4f2896df0bb7 to your computer and use it in GitHub Desktop.
値がtrue/falseのいずれかであることをテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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