mml / ruby-recaptcha (http://loonsoft.com/recaptcha/)
Ruby library for ReCAPTCHA service
$ hg clone http://bitbucket.org/mml/ruby-recaptcha/
ruby-recaptcha
The basics
The ReCaptcha::Client abstracts the ReCaptcha API for use in Rails Applications
Installing
with Rails
In recent versions of Rails, you can specify the gem in environment.rb:
Demonstration of usage
reCAPTCHA
First, create an account at ReCaptcha.net
Get your keys, and make them available as constants in your
application. You can do this however you want, but RCC_PUB, RCC_PRIV
(for regular reCaptcha) and MH_PUB, MH_PRIV (for MailHide) must be
set to their respective values (the keys you receive from reCaptcha).
It doesn't matter how you set these constants. You can create them however you like:
The ReCaptcha::Client constructor can also take an options
hash containing keys thusly:
After your keys are configured, and the gem is loaded, include the
ReCaptcha::AppHelper module in your ApplicationController:
This will mix-in validate_recap method.
Then, in the controller where you want to do the validation, chain
validate_recap() into your regular validation:
Require and include the view helper in your application_helper:
This will mix get_captcha() into your view helper.
Now you can just call get_captcha() in your view to insert
the requisite widget from ReCaptcha.
To customize theme and tabindex of the widget, you can include an options hash:
See the ReCaptcha API Documentation under "Look and Feel Customization" for more information.
Proxy support
If your rails application requires the use of a proxy, set proxy_host into your environment:
Mail Hide
When you mix in ViewHelper as above, you also get mail_hide(address, contents), which you can call in your view thusly:
Contents defaults to the first few characters of the email address.
Testing
If you want to run automated integration testing and get past your calls to validate_recap, you can redefine it in config/environments/test.rb, like so:
Now you can get past user/create in your cucumber stories!
Bugs
Code
Note the wiki & forum & such there...
License
This code is free to use under the terms of the MIT License.
Contact
Comments are welcome. Send an email to [[mailto:mlooney@gmail.com.without.spam the author]]
Contributors:
- Victor Cosby (test cleanup, additional code to style widget)
- Ronald Schroeter (proxy support suggestion & proto-patch)
- Peter Vandenberk (multi-key support, ssl support, various unit tests, test refactoring)
- Kim Griggs (found long address-newline bug)
This revision is from 2009-03-15 03:32
