If this plug-in helped you then please recommend me here.
SimpleCaptcha is the simplest and a robust captcha plugin. Its implementation requires adding up a single line in views and in controllers/models.
SimpleCaptcha is available to be used with Rails2.0 or above and also it provides the backward compatibility with previous versions of Rails.
- Zero FileSystem usage(secret code moved to db-store and image storage removed).
- Provides various image styles.
- Provides three level of complexity of images.
- Works absolutely fine in distributed environment
- Implementation is as easy as just writing a single line in your view…
“<%= show_simple_captcha %>” within the ‘form’ tags.
- Flexible DOM and CSS handling(There is a separate view partial for rednering SimpleCaptcha DOM elements).
- Automated removal of 1 hour old unmatched simple_captcha data.
- Option to create alphabetic or numeric Images.
RMagick should be installed on your machine to use this plugin.
visit http://rmagick.rubyforge.org for more details.
SimpleCaptcha plugin can be installed by running this command from the application root
ruby script/plugin install svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha
If you are unable to checkout/install the plugin via SVN. Download the archive and unzip it into /vendor/plugins directory of the rails-app.
After installation, follow these simple steps to setup the plugin. The plugin’s configuration will highly depend on the version of rails your application is using, so be specific in the following steps.
for rails >= 2.0
for rails < 2.0
add the following code in the file config/routes.rb
ActionController::Routing::Routes.draw do |map| map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha' end
This is a mandatory route used for rendering the simple_captcha image on the fly without storing on the filesystem.
add the following line in the file app/controllers/application.rb
ApplicationController < ActionController::Base include SimpleCaptcha::ControllerHelpers end
Apart from above setting up steps…
If your controller(the one through which you are implementing captcha) is not inherited from ApplicationController, it is required to add the line “include SimpleCaptcha::ControllerHelpers” in it.
In the view file within the form tags add this code
<%= show_simple_captcha %>
and in the controller’s action authenticate it as
def my_action if simple_captcha_valid? do_this else do_that end end
In the view file within the form tags write this code
<%= show_simple_captcha(:object=>"user") %>
and in the model class add this code
class User < ActiveRecord::Basse apply_simple_captcha end
Validating with captcha
NOTE: @user.valid? will still work as it should, it will not validate the captcha code.
Saving with captcha
NOTE: @user.save will still work as it should, it will not validate the captcha code.
Options & Examples
provides the custom below the image, default is “(type the code from the image)”
Provides the specific image style for the captcha image.
There are eight different styles available with the plugin as…
Default is ‘simply_blye’
You can also specify ‘random’ to select the random image style.
Handles the complexity of the image. The :distortion can be set to ‘low’, ‘medium’
or ‘high’. Default is ‘low’.
Handles the text of the captcha image. Available options are ‘numeric’ or ‘alphabetic’.
Default is ‘alphabetic’.
the name of the object of the model class, to implement the model based captcha.
How to change the CSS for SimpleCaptcha DOM elements ?
You can change the CSS of the SimpleCaptcha DOM elements as per your need in this file…
For Rails >= 2.0 the partial view file wiil reside as…
For Rails < 2.0 the partial view file will reside as…
Controller Based Example
<%= show_simple_captcha(:label => "(human authentication)") %>
<%= show_simple_captcha(:image_style => 'embosed_silver', :distortion => 'medium') %>
<%= show_simple_captcha(:image_style => 'random', :label => "(are you human ?)") %>
Model Based Example
<%= show_simple_captcha(:object => 'user', :image_style => 'simply_red', :distortion => 'medium') %>
provides the custom message on failure of captcha authentication
the default is “image did not match with text”
if set to true, adds the error message to the base.
class User < ActiveRecord::Base apply_simple_captcha end
class User < ActiveRecord::Base apply_simple_captcha :message => " image and text were different", :add_to_base => true end
Any feedback/comment/issue/donation is welcome!
Drop me a mail at sur(DOT)max(AT)gmail(DOT)com
If you like this plugin, do not forget to Recommend Me.