Included Modules

Class Index [+]

Quicksearch

Ramaze::Helper::SimpleCaptcha

Produce very simple question/answer pairs.

The default is a trivial mathematical problem.

Usage (trait is optional):

    class RegisterController < Ramaze::Controller
      trait :captcha => lambda{
        ["the answer to everything", "42"]
      }

      def index
        %(
          <form action="#{r(:answer}">
            What is #{simple_captcha}?
            <input type="text" name="answer" />"
            <input type="submit" />
          </form>
        ).strip
      end

      def answer
        check_captcha(request[:answer])
      end
    end

Constants

NUMBERS

Public Instance Methods

check_captcha(answer) click to toggle source

check the given answer against the answer stored in the session.

    # File lib/ramaze/helper/simple_captcha.rb, line 54
54:       def check_captcha(answer)
55:         return false unless captcha = session[:CAPTCHA]
56: 
57:         answer.to_s.strip == captcha[:answer].to_s
58:       end
simple_captcha() click to toggle source

Call the trait[:captcha] and store question/answer in session

    # File lib/ramaze/helper/simple_captcha.rb, line 46
46:       def simple_captcha
47:         question, answer  = ancestral_trait[:captcha].call
48:         session[:CAPTCHA] = { :question => question, :answer => answer.to_s }
49: 
50:         question
51:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.