有什么重要的差异是有Rails的开发和生产环境之间? [英] What important differences are there between Rails' development and production environments?

查看:180
本文介绍了有什么重要的差异是有Rails的开发和生产环境之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我经历了一个可怕的问题,因为钢轨的生产和开发环境之间的差异的结果。考虑code:

I experienced a horrible problem today as a result of differences between Rail's production and development environments. Consider the code:

"select * from subscription_plans where affiliate_id is null or affiliate_id = #{@subscription_plan.affiliate.id rescue 0};"

绝不会有为0的ID任何分支机构,所以如果@ subscription_plan.affiliate是nill我希望查询只返回订阅计划没有关联机构。伟大工程的开发环境,因为nil.id抛出一个错误(前提是它确实给一些消息,它应该被错误地4)。问题是,我推了code活到我的生产服务器和订阅计划用4的affiliate_id开始出现全部结束。在生产中,nil.id不会抛出一个错误,而是直接返回4.吉兹,由于轨道。

There will never be any affiliates with an id of 0, so if @subscription_plan.affiliate is nill I expected the query to return only subscription plans without an affiliate. Works great in development environment because nil.id throws an error (provided it does give some message about it should mistakenly be 4). Problem is, I pushed that code live to my production server and subscription plans with an affiliate_id of 4 started showing up all over. In production, nil.id doesn't throw an error, but rather simply returns 4. Geez, thanks rails.

所有这些要求,我应该是什么其他的东西意识到作为一个Rails开发?尤其是,是否有环境之间的其他差异是可能导致问题?

All that to ask, what other things should I be aware of as a Rails developer? In particular, are there other differences between environments that could potentially cause problems?

推荐答案

一切的的产生和发展是可配置的不同。如果你想抱怨的 S在生产,添加到您的 production.rb 文件:

Everything that's different between production and development is configurable. If you want whiny nils in production, add this to your production.rb file:

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

你看看你的配置/环境/ production.rb 配置/环境/ development.rb 文件和阅读方法/属性中的注释和文档被使用。把我的头顶部,这里有一些差异:

Just look at your config/environments/production.rb and config/environments/development.rb files and read the comments and documentation on the methods/properties being used. Off the top of my head, here are some differences:

  1. code未重装生产,所以如果你有被设置为 Time.now 1.day任何常量。前或任何开发的工作不如预期,他们不会在生产工作。
  2. 调试级别的日志消息会被忽略的生产。
  3. 在缓存时,才会启用生产
  4. 详细的错误信息只能在发展可用(尽管它们都记录到轨日志)
  1. Code is not reloaded in production, so if you have any constants that are set to Time.now or 1.day.ago or whatever in development that work as expected, they won't work in production.
  2. debug level log messages are ignored in production.
  3. caching is enabled only in production
  4. verbose error messages are only available in development (though they are logged to the rails log)

有更多的,可能的,但如果你只是检查出的配置文件,你应该得到一个什么样的差异是个好主意。

There are more, probably, but if you just check out the config files you should get a good idea of what the differences are.

此外,一个简单的code批判:

Also, a brief code critique:

  1. 救援富模式通常是一个坏主意。可能已提出合法错误将被忽略。
  2. 使用ActiveRecord的SQL插入动态值添加到SQL字符串,请不要使用#{}
  1. The rescue foo pattern is generally a bad idea. Legitimate errors that may have been raised will be ignored.
  2. Use ActiveRecord SQL interpolation to add dynamic values to a SQL string, don't use #{}.

这篇关于有什么重要的差异是有Rails的开发和生产环境之间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆