Module: ValidatesCaptcha::ModelValidation::ClassMethods

Defined in:
lib/validates_captcha/model_validation.rb

Instance Method Summary collapse

Instance Method Details

#validate_captcha?Boolean

Returns true if captcha validation is activated, otherwise false.

Returns:

  • (Boolean)


35
36
37
# File 'lib/validates_captcha/model_validation.rb', line 35

def validate_captcha? #:nodoc:
  @validate_captcha == true
end

#with_captcha_validation(&block) ⇒ Object

Activates captcha validation on entering the block and deactivates captcha validation on leaving the block.

Example:

User.with_captcha_validation do
  @user = User.new(...)
  @user.save
end


27
28
29
30
31
32
# File 'lib/validates_captcha/model_validation.rb', line 27

def with_captcha_validation(&block)
  self.validate_captcha = true
  result = yield
  self.validate_captcha = false
  result
end