- Author
-
Tilo Sloboda (www.unixgods.org/)
- Copyright
-
Copyright © 2011 Tilo Sloboda
- License
- Home
-
www.unixgods.org/~tilo/Ruby/mail_form_example_with_recaptcha.html
- Git
-
git://github.com/tilo/mail_form_example_with_recaptcha.git
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”.
* https://github.com/plataformatec/mail_form * http://pragprog.com/titles/jvrails/crafting-rails-applications
Unfortunately this example is incomplete:
* http://www.arailsdemo.com/posts/43
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.
* https://github.com/ambethia/recaptcha * http://www.google.com/recaptcha/learnmore * https://www.google.com/recaptcha/admin/create
-
Clone this repository
gem clone git://github.com/tilo/mail_form_example_with_recaptcha.git
-
Check your Gemfile and install the Gems
emacs Gemfile bundle install
-
Set-Up a reCaptcha account with Google 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
-
Customize this example to fit your needs:
-
add your reCaptcha account information / add your private and public keys
emacs config/initializers/recaptcha.rb
-
add your email settings / add your domain name and the email address where you want to receive the form data
emacs config/initializers/setup_mail.rb emacs app/models/mail_forms/contact.rb
-
check Google’s instructions on how to customizing the look and feel of reCAPTCHA
http://code.google.com/apis/recaptcha/docs/customization.html
-
you might want to change the :theme variable in the view file
emacs app/views/mail_forms/contact/new.html.erb
-
-
Try out the Example Start the Rails application: rails s
Point your browser to
firefox http://localhost:3000/contact
Enjoy!
Here’s the list of relevant files as a tree-view:
<pre> . ├── 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 │ │ …
</pre>