RMagickCaptcha is a gem that implements captcha for using in Rails application. The gem provides functionality to create a captcha image and validate user's input.

  • The gem allows multiple captchas at the same page

  • The gem supports I18n and provides locale resource

  • The gem provides rmagick_captcha controller controller to generate images

  • The gem allows …

Quick Start

In your Gemfile:

gem "rmagick_captcha", ">= 0.6.2"

In your model:

# Server create captcha_key, user input into captcha_text
has_rmagick_captcha :captcha
validate :validate_rmagick_captcha

In your controller:

download_rmagick_captcha :show

def new
  @user = User.new
  session[:user_captcha] = @user.reset_captcha_key

def create
  @user = User.new(params[:user])
  @user.captcha_key = session[:user_captcha]
  if @user.errors.empty?
    session[:user_captcha] = nil
    flash[:notice] = "Thanks for signing up!"
    session[:user_captcha] = @user.reset_captcha_key
    render :action => 'new'

In your views:

<% form_for @user, :url => users_path,
   :html => {:id => "user_form", :class => "html-form" } do |f| %>
        <%= rmagick_captcha_tag(:controller => "user", :id => "user_captcha")  %>
        <%= f.text_field :captcha_text, :maxlength => 16%>
        <%= f.error_message_on :captcha_text %>
    <%= f.submit "Submit"%>
<% end %>

In your routes.rb:

match 'user(/show)' => 'user#show', :as => :captcha

If you wish:

-Run ruby script/rails generate rmagick_captcha to gen resources such as locale files.
-Use config/initiaizers to configure options for this gem


  • Type 'gem install –local rmagick_captcha' with root account if you have installed RubyGems.


Example goes here.

Copyright © 2011 arufanov, released under the MIT license.