Require 'rails_env' taks only where we need to

Backport of 4b8b8c1b4d1b516a9ebf8e19d5a14956c5654ac8