|
Simple Captcha插件获取:svn://rubyforge.org/var/svn/expressica/plugins/simple_captcha 下载后把simple_captcha放入/vendor/plugins目录
Simple Captcha插件安装: step 1. 当rails 版本>2.0 rake simple_captcha:setup 当rails 版本<2.0 rake simple_captcha:setup_old
step 2. rake db:migrate
step 3. 在routs中添加
ActionController::Routing::Routes.draw do |map|
map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha'
end
step 4. 在application.rb中添加
ApplicationController < ActionController::Base
include SimpleCaptcha::ControllerHelpers
end Usage Controller Based In the view file within the form tags add this code [list=1]<%= show_simple_captcha %> <%= show_simple_captcha %>[/pre]and in the controller’s action authenticate it as [list=1]def my_action if simple_captcha_valid? do_this else do_that end end def my_action if simple_captcha_valid? do_this else do_that endend[/pre]Model Based In the view file within the form tags write this code [list=1]<%= show_simple_captcha(:object=>"user") %> <%= show_simple_captcha(:object=>"user") %>[/pre]and in the model class add this code [list=1]class User < ActiveRecord::Basse apply_simple_captcha end class User < ActiveRecord::Basse apply_simple_captchaend[/pre]Validating with captcha [list=1]@user.valid_with_captcha? @user.valid_with_captcha?[/pre]NOTE: @user.valid? will still work as it should, it will not validate the captcha code. Saving with captcha [list=1]@user.save_with_captcha @user.save_with_captcha[/pre]NOTE: @user.save will still work as it should, it will not validate the captcha code. 参考网址:http://expressica.com/simple_captcha/
|
一共有 0 条评论