1

我使用了以下指南: http: //www.tweetegy.com/2012/10/setting-up-a-captcha-with-recaptcha-service-and-the-captcha-gem/

我在 development.rb 中有以下内容:

ENV['RECAPTCHA_PUBLIC_KEY'] = 'keyString'
ENV['RECAPTCHA_PRIVATE_KEY'] = 'keyString'

在 config/initializers/recaptcha.rb 中:

Recaptcha.configure do |config|
  config.public_key  = RECAPTCHA_PUBLIC_KEY
  config.private_key = RECAPTCHA_PRIVATE_KEY
end

在开发中运行 rails server 时出现以下错误:

Exiting                                                                                                                                           
/home/action/visualhaggard.org/config/initializers/recaptcha.rb:2:in `block in <top (required)>': uninitialized constant RECAPTCHA_PUBLIC_KEY (Nam
eError)

有没有人遇到并解决了这个问题?我有错字吗?谢谢。

4

1 回答 1

3

该示例未在环境变量中定义 RECAPTCHA_PUBLIC_KEY。它只是将其定义为常数。

#put this in development.rb and in production.rb (separate keys in each so you can test!)
RECAPTCHA_PUBLIC_KEY= 'your-public-key'
RECAPTCHA_PRIVATE_KEY= 'your-private-key'
于 2013-08-18T15:27:43.823 回答