Rails 3 环境变量属于哪里?

发布于 2024-09-25 09:13:40 字数 529 浏览 0 评论 0原文

我对 Ruby on Rails 3 比较陌生,希望将 Ambethia 的 Recaptcha 插件集成到我的应用程序中。

在下面看起来像 Rails 2 文档的内容中,要求将以下内容放入environment.rb中,

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

这与 Rails 3environment.rb 文件的关系到底在哪里,目前如下所示:

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

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

I'm relatively new to Ruby on Rails 3 and hope to integrate Ambethia's Recaptcha plugin into my app.

In following what looks like Rails 2 documentation, it's asked to place the following into environment.rb

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

Where exactly does this go in relation to the Rails 3 environment.rb file, which currently looks like the following:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○闲身 2024-10-02 09:13:40

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

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 %>

in rails 3, you can use your Rails::Application class like a singleton so, you can add directly

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

And after you can access to this data by

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

No more needed you ENV data.

In your controller a simple line works.

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

And in view

<%= recaptcha_tags :public_key => TestApp::Application.config.recaptcha_public_key %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文