Rails captcha in ubuntu system

Use rails scale to init the captcha.

I use a gem called simple_captcha , before you use this gem , first you must install the imagemagick , for the save , tap the command below:

sudo apt-get install imagemagick
sudo apt-get install libmagickcore-dev
sudo apt-get install libmagickwand-dev

Then add a line in the rails dir's Gemfile:

gem 'simple_captcha', :git => 'git://github.com/galetahub/simple-captcha.git'

bundle install

Init the simple_captcha config:

SimpleCaptcha.setup do |captcha_config|
  captcha_config.tmp_path = Rails.root + 'tmp'
  captcha_config.image_style = 'simply_red'
end

If there is no error , the rest option will so simple .


Include the helper in the application_comtroller.rb

class ApplicationController < ActionController::Base
  include SimpleCaptcha::ControllerHelpers
end


In the view file :

<p><%= @output %></p>

<form method="get" action="" >
  <%= show_simple_captcha(:label => 'enter',:placeholder=>'place')%>
<input type="submit" value="submit" />
</form>


In the controller action:

    if simple_captcha_valid?
      @output = 'right'
    else
      @output = 'error'
    end


For more information , please read the README file in this site : https://github.com/galetahub/simple-captcha

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值