Module: QuickCaptcha::ControllerValidation

Includes:
CaptchaUtils
Defined in:
lib/quick_captcha/controller_validation.rb

Overview

:nodoc

Instance Method Summary collapse

Methods included from CaptchaUtils

#generate_simple_captcha_key, #simple_captcha_key, simple_captcha_matches?, #simple_captcha_matches?, simple_captcha_passed!, #simple_captcha_passed!, #simple_captcha_value, simple_captcha_value

Instance Method Details

#quick_captcha_valid?Boolean

This method is to validate the simple captcha in controller. It means when the captcha is controller based i.e. :object has not been passed to the method show_simple_captcha.

Example

If you want to save an object say @user only if the captcha is validated then do like this in action…

if simple_captcha_valid?
 @user.save
else
 flash[:notice] = "captcha did not match"
 redirect_to :action => "myaction"
end

Returns:

  • (Boolean)


21
22
23
# File 'lib/quick_captcha/controller_validation.rb', line 21

def quick_captcha_valid?
  simple_captcha_valid?
end

#simple_captcha_valid?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/quick_captcha/controller_validation.rb', line 25

def simple_captcha_valid?
  if captcha = params[:captcha]
    result = simple_captcha_matches?(captcha)
    simple_captcha_passed! if result
    result
  else
    false
  end
end