taito 发表于 2013-1-29 07:43:40

用Rails Captcha插件,轻松实现验证码

 Simple Captcha 插件

可以帮我们在Rails 中轻松的实现验证码功能。

并且,他所提供的选项足以满足我们的验证要求,使用简单。支持图片和数字验证。
http://www.agoit.com/upload/attachment/60833/c0f0254b-48d8-3d49-84e5-dc5a4d7e5948.jpg    http://www.agoit.com/upload/attachment/60835/5098980e-c1ec-3836-8cd8-58c3874a5174.jpg
下载

下载地址:Download the archive
 
放入plugins中。
 
设置

<strong /> 
第一步
 
如果是rails 2.0 以上
 
rake simple_captcha:setup 
如果是rails 2.0 以下
 
rake simple_captcha:setup_old 
第二步
 
迁移数据库
 
rake db:migrate 
第三步
 
添加下列代码到config/routes.rb
 
map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha'  
第四步
 
添加下面一行到 app/controllers/applications.rb
 
ApplicationController < ActionController::Base   include SimpleCaptcha::ControllerHelpers   end 
使用

 
在view 文件中放入下面的tags代码
 
<%= show_simple_captcha %> 
添加controller 的 action ,如:
 
def my_action   if simple_captcha_valid?       do_this   else      do_that   endend  
 
参数和例子

 
view 参数
 
:label
用于显示在验证码图片旁边的文字提示
 
:image_style
图版样式
 

simply_blue
simply_red
simply_green
embosed_silver
all_black
distorted_black
charcoal_grey
almost_invisible
 
默认是 'simply_blue'' 
 
:distortion
操纵图片的扭曲度,有'low', 'medium', 'high' 三个选项
 
默认是 'low'
 
:code_type
代码类型,有数字和图片两种类型可选。 'numeric', 'alphabetic'
 
默认是'alphabetic'
 
:object
与model class绑定时,所对应的名字
 
如何改变SimpleCaptcha DOM 的css?
2.0以上的,请修改 /app/views/simple_captcha/_simple_captcha.erb 文件
2.0以下的,请修改 /app/views/simple_captcha/_simple_captcha.rhtml 文件
 
===============================
想了解更多,请阅读原文:
 
http://expressica.com/simple_captcha/
 
 
页: [1]
查看完整版本: 用Rails Captcha插件,轻松实现验证码