Repository is archived
No commit activity in last 3 years
No release in over 3 years
Merb plugin that provides helpers for recaptcha.net service
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0.9.3
>= 1.1.0

Runtime

~> 2.0
>= 1.0.0
 Project Readme

merb-recaptcha¶ ↑

About¶ ↑

Merb-recaptcha is plugin for Merb web-framework. It provides view and controller helpers for Recaptcha service.

Installation¶ ↑

Install gem from github.com:

gem install merb-recaptcha --source=http://gemcutter.org

Add following line in config/dependencies.rb of your web application:

dependency "merb-recaptcha", "~> 1.0.0", :require_as => "merb-recaptcha"

Sign up at Recaptcha and get public and private keys. Add keys in config/init.rb:

Merb::BootLoader.after_app_loads do
  Merb::Plugins.config[:merb_recaptcha][:public_key] = "... here your public key ..."
  Merb::Plugins.config[:merb_recaptcha][:private_key] = "... here your private key ..."
end

Usage¶ ↑

Just add helper in your form:

<%= form_for @users, :action => resource(:users), :method => :post do %>
  .....
  <%= recaptcha_tags %>
  <%= submit "Send" %>
<% end %>

And then check captcha in controller:

class Users < Application
  ......
  def create(user)
    @user = User.new(user)
    if (captcha_correct = recaptcha_valid?) && @user.save
      redirect resource(@user)
    else
      unless captcha_correct
        @user.valid?
        @user.errors.add(:general, "Captcha code is incorrect")
      end
    end
    render :new
  end
  ......
end