Module: ValidationExtensions
- Defined in:
- lib/isbn_validation.rb
Overview
The base module that gets included in ActiveRecord::Base. Validates whether the value of the specified attribute is a proper ISBN number. Defaults to verifying that the value is either a valid ISBN-10 or ISBN-13 number but this behavior can be modified using configuration options (as shown below).
class Book < ActiveRecord::Base
validates :isbn, isbn_format: true
# validates :isbn10, isbn_format: { with: :isbn10 }
# validates :isbn13, isbn_format: { with: :isbn13 }
end
Configuration options:
-
:message
- A custom error message (default is: “is not a valid ISBN”) -
:with
- A symbol referencing the type of ISBN to validate (:isbn10 or :isbn13) -
:allow_nil
- If set to true, skips this validation if the attribute isnil
(default isfalse
). -
:allow_blank
- If set to true, skips this validation if the attribute is blank (default isfalse
). -
:on
- Specifies when this validation is active (default is:save
, other options:create
,:update
). -
:if
- Specifies a method, proc or string to call to determine if the validation should occur (e.g.:if => :allow_validation
, or:if => Proc.new { |user| user.signup_step > 2 }
). The method, proc or string should return or evaluate to a true or false value. -
:unless
- Specifies a method, proc or string to call to determine if the validation should not occur (e.g.:unless => :skip_validation
, or:unless => Proc.new { |user| user.signup_step <= 2 }
). The method, proc or string should return or evaluate to a true or false value.
Defined Under Namespace
Modules: IsbnValidation