如何在rails app中初始化recaptcha?

时间:2013-08-18 15:10:25

标签: ruby-on-rails recaptcha

我使用了以下指南: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)

有没有人遇到并解决了这个问题?我有拼写错误吗?感谢。

1 个答案:

答案 0 :(得分: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'