您的位置:首页 > 大数据 > 人工智能

Rails captcha in ubuntu system

2013-11-29 14:38 387 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: