Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple Question Based Captcha
class User < ActiveRecord::Base
attr_accessor :captcha_answer
attr_writer :captcha_question
def captcha_question
@captcha_question ||= captcha_questions.to_a[rand(a.length)].first
end
def captcha_questions
{ 'What is one plus one?' => ['two', '2'],
'What number comes after 8?' => ['nine', '9'] }
end
validates :check_captcha
private
def check_captcha
captcha_questions[captcha_question].include?(captcha_answer.to_s)
end
end
<%= f.hidden_field :captcha_question %>
<%= f.label :captcha_answer, 'Are you human?' %>
<%= f.text_field :captcha_answer %>
Owner

mikel commented Aug 27, 2011

Really simple captcha implementation for Active Record models, this has been implemented as a gem, raptcha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment