Adding a reCAPTCHA to enki

Anton Jenkins | March 04, 2009

There are several techniques to help prevent spam in your blog comments. I’ve opted for a captcha using the popular reCAPTCHA system. This post will show you how to apply reCAPTCHA to the enki blogging engine.

The idea with enki is that you clone the basic master tree and then merge in features you want from other people’s trees. So the following steps will show you how to take a basic enki blog from github and merge in the recaptcha branch to keep spam away.

Step 1 : Register at recaptcha.net and install the recaptcha gem.

When you sign up and register your domain at recaptcha.net they will give you two keys – a public key and private key. Keep these keys handy as you’ll need them later on.

Install the recaptcha gem with :

1
sudo gem install ruby-recaptcha

Step 2 : Clone enki and make a branch for your own blog

Assuming your blog is going to be called “myblogname” :

1
2
3
git clone git://github.com/xaviershay/enki.git myblogname
cd myblogname
git checkout -b myblogname

Step 4 : Merge in the reCAPTCHA branch

1
2
git remote add recaptcha git://github.com/antonjenkins/enki.git
git pull recaptcha recaptcha

Now we should have a branch call myblogname with a clean install of enki merged with the recaptcha branch.

Step 5 : Configure the blog to use your reCAPTCHA keys

If you look in the environment.rb file you should see a little section right at the top for you to paste your public and private keys :

1
2
3
4
5
# config/environment.rb

# reCAPTCHA keys. Obtain these for your domain from http://recaptcha.net/
RCC_PUB = "Put your reCAPTCHA public key in here"
RCC_PRIV = "Put your reCAPTCHA private key in here"

Step 6 : Configure enki as usual

That concludes the specific steps needed for the reCAPTCHA support. All that remains is to follow Xavier Shay’s instructions for configuring enki as detailed on the enki github page :

1
2
3
4
5
6
  cp config/database.example.yml config/database.yml
  # Edit config/enki.yml and config/database.yml to taste
  rake db:migrate
  rake spec
  ./script/server
  # Load http://localhost:3000/admin in your browser

Now when you upload your blog to the web your comments form should be protected with reCAPTCHA. You probably wont see the reCAPTCHA on your development box because usually the public and private reCAPTCHA keys only work on the domain you’ve specified when you requested them (unless you checked the global box).

Resources

comments powered by Disqus