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};"
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.
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?
Everything that’s different between production and development is configurable. If you want whiny
nils in production, add this to yourproduction.rbfile:Just look at your
config/environments/production.rbandconfig/environments/development.rbfiles and read the comments and documentation on the methods/properties being used. Off the top of my head, here are some differences:Time.nowor1.day.agoor whatever in development that work as expected, they won’t work in production.debuglevel log messages are ignored in production.There are more, probably, but if you just check out the config files you should get a good idea of what the differences are.
Also, a brief code critique:
rescue foopattern is generally a bad idea. Legitimate errors that may have been raised will be ignored.#{}.