The following steps demostrate how to re-produce the NameError.
git clone https://github.com/acenqiu/name_error_test.git
bundle install
rake db:create RAILS_ENV=production
rails console production
Edit the file application_controller.rb, comment out following line.
# rescue_from ActiveRecord::RecordInvalid, with: :show_errors
Run the production console again.
rails c production
And you should see the error raised.
~/Documents/name_error_test/app/controllers/application_controller.rb:6:in `<class:ApplicationController>': uninitialized constant ActiveRecord::RecordInvalid (NameError)
If we disable eager_load in production.rb, everything is fine, but this is not what I want. No matter which action controller I put the rescue_from ActiveRecord::RecordInvalid in, the error still exists.
rescue_from ActiveRecord::RecordNotFound will survive from this error.