2010-09-28 106 views
1

我对Ruby on Rails 3比较陌生,希望将Ambethia的Recaptcha插件集成到我的应用中。Rails 3环境变量属于哪里?

在下面是什么样子的Rails 2文件,它要求将以下进入的environment.rb

ENV['RECAPTCHA_PUBLIC_KEY'] = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy' 
ENV['RECAPTCHA_PRIVATE_KEY'] = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx' 

到底在哪这是否去相对于Rails 3的environment.rb文件中,目前看起来像以下内容:

# Load the rails application 
require File.expand_path('../application', __FILE__) 

# Initialize the rails application 
Testapp::Application.initialize! 

回答

3
在轨道3,你可以像使用一个单让你的Rails ::应用类

,你可以直接添加

module TestApp 
class Application < Rails::Application 
    config.recaptcha_public_key = 'XXX' 
    config.recaptcha_private_key = 'XXX' 
end 
end 

而后就可以通过

TestApp::Application.config.recaptcha_public_key 
TestApp::Application.config.recaptcha_private_key 

访问这些数据没有更多需要你ENV数据。

在你的控制器中有一条简单的线条。

verify_recaptcha(:private_key => TestApp::Application.config.recaptcha_private_key) 

,并鉴于

<%= recaptcha_tags :public_key => TestApp::Application.config.recaptcha_public_key %>