Software Development | Ruby on Rails
brain_buster plugin

rsanheim's brain_buster is one of the plugins used in altered_beast.

The brain_buster intro says it as well as I could:

BrainBuster is a logic captcha for Rails. A logic captcha attempts to detect automated responses (ie spambots) by asking a simple question, such as a word puzzle or math question. Logic captchas are often easier for humans to answer then image based captchas, but can exclude foreign users or users with cognitive disabilities.

I can't comment on how secure a logic capture is but I do like this idea as image captchas annoy me.

Altered_beast can use brain_buster for authentication but has brain_buster deactivated by default. If you want to activate it then you'll have to add a filter to the relevant controller (users) and add the _captcha partial in the right view. altered_beast has all the code ready but it is commented out.

app/views/users/new.html.erb

Open up new.html.erb and uncomment the code on this line:

app/views/users/new.html.erb

<%#= render :partial => 'captcha' # enable for brainbuster %>

Making it:

<%= render :partial => 'captcha' # enable for brainbuster %>

By the way, RadRails really objected to the line above and removing the comment didn't cure the problem. I removed the comment then cut and pasted the line into its original position. After that RadRails was happy.

app/controllers/users_controller.rb

You also have to set the filters in users_controller.rb. Change:

app/controllers/users_controller.rb

# Brainbuster Captcha
# before_filter :create_brain_buster, :only => [:new]
# before_filter :validate_brain_buster, :only => [:create]

To:

# Brainbuster Captcha
before_filter :create_brain_buster, :only => [:new]
before_filter :validate_brain_buster, :only => [:create]

Since we're in users_controller.rb its worth mentioning that it contains a method called render_or_redirect_for_captcha_failure. This method is invoked when the captcha fails and is an override of the default method in vendor/plugins/brain_buster/lib/brain_buster_system.rb