Module: ActiveModel::Validations::HelperMethods
- Defined in:
- lib/flag_shih_tzu/validators.rb
Overview
Use these validators in your model
Instance Method Summary collapse
-
#validates_presence_of_flags(*attr_names) ⇒ Object
Validates that the specified attributes are flags and are not blank.
Instance Method Details
#validates_presence_of_flags(*attr_names) ⇒ Object
Validates that the specified attributes are flags and are not blank.
Happens by default on save. Example:
class Spaceship < ActiveRecord::Base
include FlagShihTzu
has_flags({ 1 => :warpdrive, 2 => :hyperspace }, :column => ‘engines’)
validates_presence_of_flags :engines
end
The engines attribute must be a flag in the object and it cannot be blank.
Configuration options:
- :message - A custom error message (default is: “can’t be blank”).
- :on - Specifies when this validation is active. Runs in all
validation contexts by default (+nil+), other options are :create
and :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 { |spaceship| spaceship.warp_step <= 2 }). The method,
proc or string should return or evaluate to a true or false value. - :strict - Specifies whether validation should be strict.
See ActiveModel::Validation#validates! for more information.
66 67 68 |
# File 'lib/flag_shih_tzu/validators.rb', line 66 def validates_presence_of_flags(*attr_names) validates_with(PresenceOfFlagsValidator, _merge_attributes(attr_names)) end |