public
Description: ReCaptcha helpers for Rails apps
Homepage: http://ambethia.com/recaptcha
Clone URL: git://github.com/ambethia/recaptcha.git
Click here to lend your support to: recaptcha and make a donation at www.pledgie.com !
ambethia (author)
Sat Sep 12 16:25:36 -0700 2009
commit  c63cd3f8542da0854a2c910fbff1ab30d27886b8
tree    7364cb5b3aacee9d8b1500bfeaf7dae78a30d414
parent  a6bafebb4459d10982b241f5f89bc15f1802c968
name age message
file .gitignore Sat Sep 12 16:39:47 -0700 2009 Version bump to 0.2.0 (<3 Jeweler) [ambethia]
file CHANGELOG Sat Sep 12 16:04:48 -0700 2009 Gemified for version 0.1.0 [mwhuss]
file LICENSE Sat May 26 02:35:19 -0700 2007 Initial import of ReCAPTCHA plugin [ambethia]
file Manifest Loading commit data...
file README.rdoc
file Rakefile
file VERSION
file init.rb
directory lib/ Sat Sep 12 16:04:48 -0700 2009 Gemified for version 0.1.0 [mwhuss]
file recaptcha.gemspec Sat Sep 12 16:39:47 -0700 2009 Version bump to 0.2.0 (<3 Jeweler) [ambethia]
directory tasks/ Sat May 26 02:35:19 -0700 2007 Initial import of ReCAPTCHA plugin [ambethia]
directory test/
README.rdoc

ReCAPTCHA

Author:Jason L Perry (ambethia.com)
Copyright:Copyright © 2007 Jason L Perry
License:MIT
Info:ambethia.com/recaptcha/
Git:github.com/ambethia/recaptcha/tree/master
Bugs:github.com/ambethia/recaptcha/issues

This plugin adds helpers for the ReCAPTCHA API (recaptcha.net/). In your views you can use the recaptcha_tags method to embed the needed javascript, and you can validate in your controllers with verify_recaptcha.

You’ll want to add your public and private API keys in the environment variables RECAPTCHA_PUBLIC_KEY and RECAPTCHA_PRIVATE_KEY, respectively. You could also specify them in config/environment.rb if you are so inclined. Exceptions will be raised if you call these methods and the keys can’t be found.

recaptcha_tags

Some of the options available:

:ssl:Uses secure http for captcha widget (default false)
:noscript:Include <noscript> content (default true)
:display:Takes a hash containing the theme and tabindex options per the API. (default nil)
:public_key:Your public API key, takes precedence over the ENV variable (default nil).
:error:Override the error in +session[:recaptcha_error]+ (default nil).

verify_recaptcha

This method returns true or false after processing the parameters from the ReCAPTCHA widget. Why isn’t this a model validation? Because that violates MVC. Use can use it like this, or how ever you like. Passing in the ActiveRecord object is optional, if you do—and the captcha fails to verify—an error will be added to the object for you to use.

Some of the options available:

:model:Model to set errors
:message:Custom error message
  respond_to do |format|
    if verify_recaptcha(:model => @post, :message => 'Oh! It's error with ReCaptcha!') && @post.save
      # ...
    else
      # ...
    end
  end

TODO

  • Remove Rails/ActionController dependencies
  • Framework agnostic
  • Add some helpers to use in before_filter and what not
  • Better documentation