验证码生成插件simple_captcha

插件地址:[url]https://github.com/eshopworks/simple_captcha[/url]

[b](1)入门篇:[/b]
安装插件-->
script/plugin install git://github.com/eshopworks/simple_captcha.git


执行-->
rake simple_captcha:setup


在routes.rb中添加-->
map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha'


你还需要在application_controller.rb中加入-->
ApplicationController < ActionController::Base
include SimpleCaptcha::ControllerHelpers
end


根据我的项目,需要在app/views/events/new.html.erb的form中加上-->
 <p>
<%= show_simple_captcha(:object => 'event') %>
</p>


在app/models/event.rb中添加-->

class Event < ActiveRecord::Base
apply_simple_captcha
end


将app/controllers/events_controller.rb中的create action-->
if @event.save


改为-->
if @event.save_with_captcha


[b](2)进阶篇[/b]
在插件下载的Wiki里,有一个链接,是关于此插件的详细用法的,如下-->
Simple Captcha:[url]http://expressica.com/simple_captcha/[/url]

如需要进阶使用,可以根据里面的说明进行相关修改,如->
[quote]:label
provides the custom below the image, default is “(type the code from the image)”

:image_style
Provides the specific image style for the captcha image.
There are eight different styles available with the plugin as…

* simply_blue
* simply_red
* simply_green
* embosed_silver
* all_black
* distorted_black
* charcoal_grey
* almost_invisible

Default is ’simply_blye’
You can also specify ‘random’ to select the random image style.

:distortion
Handles the complexity of the image. The :distortion can be set to ‘low’, ‘medium’
or ‘high’. Default is ‘low’.

:code_type
Handles the text of the captcha image. Available options are ‘numeric’ or ‘alphabetic’.
Default is ‘alphabetic’.

:object
the name of the object of the model class, to implement the model based captcha.[/quote]

看看我的应用-->
在user.rb中
apply_simple_captcha :message => "image and text were different", :add_to_base => true


在对应的new.html.erb里
<p>验证码</p>
<%= show_simple_captcha(:object => 'user', :code_type => 'numeric', :image_style => 'all_black', :distortion => 'low',:label => "(请正确输入图片中的数字?)") %>


因此它看起来应该是这样的-->
[img]http://dl.iteye.com/upload/picture/pic/79903/fa4a5dc5-6952-3a60-acdc-09b28445ebdc.jpg[/img]

[b](3)实操篇:[/b]
从上图可以看到,这种样式其实是很丑的.而且也没有刷新验证码的按钮.反正就是不顺眼.废话不说了,看看netfork兄的文章吧.
验证码生成换成simple_captcha了:[url]http://netfork.iteye.com/blog/434099[/url]

以上东东只供记录.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值