Rails 环境最佳实践

Rails Environments Best Practices

我一直主要在本地开发 rails(在开发环境中),并且需要使网站很快在 nginx、ec2 上运行。我知道 rails 项目附带三个环境。我有几个关于切换环境的开放式问题可以帮助我加速这个过程。

  1. 在ec2的"production"环境中运行有多大必要?换句话说,简单地 运行 与我 运行 开发的相同 "development" 环境有什么缺点?

  2. 我浏览了 "Configuring Rails Application" 教程 (http://guides.rubyonrails.org/configuring.html),但它对我来说大多是胡言乱语。根据您的经验,从开发到生产阶段需要对配置文件进行(或强烈鼓励)哪些主要更改?

  3. 关于环境,您还有什么建议吗?

非常感谢!

How necessary is it to run in the "production" environment in ec2? In other words, what are the cons of simply running the same "development" environment that I've been running to develop?

开发环境旨在公开大量可能有助于您调试应用程序的内部信息。您不想将它们暴露给用户,尤其是在出现异常的情况下。

风险是暴露内部的私有数据,例如连接字符串。

此外,开发环境设计为在每次请求时重新加载 类,有效地减慢了很多请求的流程。这同样适用于资产管道,它被设计为在运行时重新编译。

最后但同样重要的是,gem 和库依赖于开发不需要 "safe" 的事实。你真的不想打破这个假设。

I skimmed through the "Configuring Rails Application" tutorial (http://guides.rubyonrails.org/configuring.html) but it mostly sounds like jibberish to me. From your experiences, what are major changes that need to be made (or highly encouraged) in the config files when going from development to production?

从默认值开始。它们适用于大多数情况。随着时间的推移,您会对其进行调整。

Anything else that you'd recommend regarding environments?

如果您想使用 Rails,请遵循 Rails 约定。 ;)