Module: Ramaze::Helper::SimpleCaptcha
- Includes:
- Traited
- Defined in:
- lib/ramaze/helper/simple_captcha.rb
Overview
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
Constant Summary
- NUMBERS =
[5, 10, 15, 20]
Instance Method Summary (collapse)
-
- (Object) check_captcha(answer)
check the given answer against the answer stored in the session.
-
- (Object) simple_captcha
Call the trait[:captcha] and store question/answer in session.
Instance Method Details
- (Object) check_captcha(answer)
check the given answer against the answer stored in the session.
53 54 55 56 57 |
# File 'lib/ramaze/helper/simple_captcha.rb', line 53 def check_captcha(answer) return false unless captcha = session[:CAPTCHA] answer.to_s.strip == captcha[:answer].to_s end |
- (Object) simple_captcha
Call the trait[:captcha] and store question/answer in session
45 46 47 48 49 50 |
# File 'lib/ramaze/helper/simple_captcha.rb', line 45 def simple_captcha question, answer = ancestral_trait[:captcha].call session[:CAPTCHA] = { :question => question, :answer => answer.to_s } question end |