recaptcha

安装

gem "recaptcha", :require => "recaptcha/rails"

基本配置

(因为用的是第三方 google 的产品,所以你得有接口)

申请后,可以在 config/initializers/recaptcha.rb 这么写:

Recaptcha.configure do |config|
  config.public_key  = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
  config.private_key = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
  config.proxy = 'http://myrpoxy.com.au:8080'
end

基本使用

在视图表单里你有这个 辅助方法 :

recaptcha_tags(options = {})

其可选参数有以下几个 :

:ssl
Uses secure http for captcha widget (default false)

:noscript
Include <noscript> content (default true)

:display
Takes a hash containing the theme and tabindex options per the API. (default nil)

:ajax
Render the dynamic AJAX captcha per the API. (default false)

:public_key
Your public API key, takes precedence over the ENV variable (default nil)

:error
Override the error code returned from the reCAPTCHA API (default nil)

在控制器里你有这个方法

verify_recaptcha(options = {})

其返回值为 ture 或者 false

其可选参数有以下几个 :

:model
Model to set errors

:attribute
Model attribute to receive errors (default :base)

:message
Custom error message

:private_key
Your private API key, takes precedence over the ENV variable (default nil).

:timeout
The number of seconds to wait for reCAPTCHA servers before give up. (default 3)

你可能感兴趣的:(recaptcha)