rying to create a conditional override for rails error output (suitable for certain situations where you would speed up feedback/review loop from a divided review group – one that should see error messages, and one that has no use for them)
Working with Rails 7.2.2.1
The global override “config.consider_all_requests_local” does work for me, in config/environments/development.rb - I can switch off the error messages in dev mode by setting that to “false”
But seeking granular, runtime control – googling suggests to define/override the
“def local_request?” method. Suggestions include adding the method to ActionController::Rescue
I have tried to do that in application.rb and under initializers/my_custom_inits.rb
Has no effect – rails is still honoring the “config.consider_all_requests_local = false” flag
I have tried the following in various startup scopes:
ActionController::Rescue.module_eval do
def local_request?
true # set to true for testing (later have runtime conditionals)
end
end
Not overriding the (overriding) config flag (essentially – seeking to override the override, conditionally)
So if you wanted to override it conditionally, you would set config.consider_all_requests_local = false in your config (because that gets assigned to the rack request env) and then define a dynamic ApplicationController#show_detailed_exceptions? method. … or just assign the rack request env in a before_action.
You’re trying to conditionally override local_request? in Rails 7.2.2.1, but Rails still respects config.consider_all_requests_local. This is because Rails prioritizes that config setting.
Solution (short and to the point):
Override local_request? in your ApplicationController, not via ActionController::Rescue:
class ApplicationController < ActionController::Base
def local_request?
# Your conditional logic here
some_condition ? true : false
This allows runtime control per request. Make sure config.consider_all_requests_local is not set to force true/false, or your method won’t be called.