Rails 3 - 设置环境
我有一个 Rails 3 应用程序(我已升级)。它在乘客和 nginx 上运行,但在我的生产服务器上,它也以设置为“生产”的环境启动。我知道我错过了一些非常基本的东西,但我只是不知道在哪里设置环境而不是在environment.rb中。
感谢您的帮助!
更新:好的,我了解到我仍然可以使用 Rails.env = 'product' 来做到这一点。
这对我来说似乎有点老套。你知道在 Capfile 或类似的东西中配置这个的优雅方法吗?
I have a rails 3 app (which I upgraded). It runs on passenger and nginx but on my production server it also starts with the environment set to 'production'. I know I am missing something really basic, but I just can't figure out where to set the environment instead of in environment.rb.
Thanks for helping!
UPDATE: ok, I learned I can still do that with Rails.env = 'production'.
That seems kind of old school to me. Do you know an elegant way to configure this maybe in the Capfile or sth like that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Rails 3 与 Rails 2.x 略有不同,因为它有一个 config.ru 文件,就像其他 Rack 应用程序一样。
Passenger 将 Rails 检测为 Rack 应用程序,因此您必须在虚拟主机中使用 RackEnv 而不是 RailsEnv。您可以根据 Passenger/Nginx 的文档使用 RackEnv 设置环境。
Rails 3 is a little bit different than Rails 2.x in that it has a config.ru file, like other Rack applications.
Passenger detects rails as a Rack app, so you'll have to use RackEnv instead of RailsEnv in the vhost. You can set the environment using RackEnv as per the documentation for Passenger/Nginx.
您可以为带有乘客的 nginx 的虚拟主机中的每个应用程序配置不同的 RAILS_ENV。我从未使用过 nginx,但在 apache 中它只是一个
RailsEnv=development
指令。这样每个站点就可以设置它,不用担心配置上限任务或变量或任何东西。请参阅文档。请注意,默认值为生产
,因此应该已经为您设置好了。You can configure a different RAILS_ENV for each app in your vhost for nginx with passenger. I've never used nginx but in apache it's just a
RailsEnv=development
directive. That way each site just has it set, no worries with configuring a cap task or variable or anything. See the docs. Note that the default isproduction
so this should already be set for you.