Step-by-Step mail_form gem example with reCaptcha gem for Rails 3

Step-by-Step mail_form gem example with reCaptcha gem for Rails 3

Tilo Sloboda, 2011-Apr-11

Summary

This example Rails 3 application show you how to: You download the complete Rails 3 app with all code from GitHub, here: http://github.com/tilo/mail_form_example_with_recaptcha e.g.:

git clone http://github.com/tilo/mail_form_example_with_recaptcha

 

The mail_form Gem

The mail_form gem allows you to create forms directly in Rails 3 without a database backend. As soon as you submit the form, it gets emailed to an address you specify.

You might have read about the mail_form gem either on the web or in the Pragmatic Programmer's book "Crafting Rails Applications".

Unfortunately this example is incomplete:

reCaptcha Gem

The recaptcha gem allows you to make sure that a human (not a bot) is submitting your forms. The recaptcha gem uses Google's ReCAPTCHA service. ReCAPTCHA is a free CAPTCHA service that helps to digitize books, newspapers and old time radio shows.

Getting Started

  1. Clone this repository
  2. gem clone git://github.com/tilo/mail_form_example_with_recaptcha.git

  3. Check your Gemfile and install the Gems
  4. emacs Gemfile bundle install

  5. Set-Up a reCaptcha account with Google
  6. By default, your reCAPTCHA key is restricted to the specified domain, and any subdomains for additional security. This is why you need to sign-up, to get your API-key for your specific domain.

    https://www.google.com/recaptcha/admin/create

  7. Customize this example to fit your needs:
  8. Try out the Example
  9. Start the Rails application:

    rails s

    Point your browser to

    firefox http://localhost:3000/contact

 

Enjoy!

 

Appendix

Here's the list of relevant files as a tree-view:
.
├── app
│   ├── controllers
│   │   ├── ...
│   │   └── mail_forms
│   │       └── contact_controller.rb
│   │   ...
│   ├── models
│   │   └── mail_forms
│   │       └── contact.rb
│   │   ...
│   └── views
│       └── mail_forms
│           └── contact
│               └── new.html.erb
│   ...
├── config
│   │   ...
│   ├── initializers
│   │   ├── recaptcha.rb
│   │   └── setup_mail.rb
│   │   ...