Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3环境变量属于哪里?_Ruby On Rails_Variables_Environment - Fatal编程技术网

Ruby on rails Rails 3环境变量属于哪里?

Ruby on rails Rails 3环境变量属于哪里?,ruby-on-rails,variables,environment,Ruby On Rails,Variables,Environment,我对RubyonRails3比较陌生,希望将Ambethia的Recaptcha插件集成到我的应用程序中 在下面的Rails 2文档中,要求将以下内容放入environment.rb ENV['RECAPTCHA_PUBLIC_KEY'] = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy' ENV['RECAPTCHA_PRIVATE_KEY'] = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx' 与Rails 3

我对RubyonRails3比较陌生,希望将Ambethia的Recaptcha插件集成到我的应用程序中

在下面的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!

在Rails3中,您可以像使用单例一样使用rails::Application类,因此可以直接添加

module TestApp
 class Application < Rails::Application
    config.recaptcha_public_key = 'XXX'
    config.recaptcha_private_key = 'XXX'
 end
end
不再需要您的环境数据

在控制器中,一条简单的线路起作用

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

<%= recaptcha_tags :public_key => TestApp::Application.config.recaptcha_public_key %>
TestApp::Application.config.recaptcha\u public\u key%>
<%= recaptcha_tags :public_key => TestApp::Application.config.recaptcha_public_key %>