Purpose of "Consider_All_Requests_Local" in Config/Environments/Development.Rb

Purpose of consider_all_requests_local in config/environments/development.rb?

Non-local requests result in user-friendly error pages. Local requests, assumed to come from developers, see a more useful error message that includes line numbers and a backtrace. consider_all_requests_local allows your app to display these developer-friendly messages even when the machine making the request is remote.

Why consider_all_requests_local fails with rspec config

Ok I found quite easy solution

before do
Rails.application.config.consider_all_requests_local = false
load "application_controller.rb"
end

after do
Rails.application.config.consider_all_requests_local = true
load "application_controller.rb"
end

It is part of anonymous application controller test suite.

You have to add after block... because this change will persist through other suites.

Any improvements welcome :D

edit: Using spork and guard causes for me sometimes random errors... before :all seems to solve that problem

Rails 3 - development errors in production mode

Move your root declaration up to the "server" block so the server can use the Rails app defined error handling pages when it receives a 5XX, 4XX error.

Or add error_page directives to the location block where passenger is being used so the error handlers can resolve the public/5xx.html in the Rails app public directory when needed.

If your app is not serving up the page and nginx has no visibility to the static page then it can't serve the page you want.

Testing with rspec .consider_all_requests_local = false

The issue looks to be caused by your unless check being performed at class load time. This means the very first time the class is loaded the value in the application config is checked and the rescue_from is either set or not set.

At the most basic workaround, you would need to use load to cause that file to get re-read once the setting has been changed. However, as is, once the rescue_from is turned on, loading the file again won't cause it to turn off.

The next alternative is to use rescue_from(with:) which delegates to a helper or the block form. You can use this helper to check the value and either handle the condition or not. However, considering this looks to be something you only want to do in a non-production environment, you could combine the two. Use the unless to verify that you are not in production, then use the with to check the config each time.

Something like:

class ApplicationController < ActionController::Base
unless Rails.env.production?
rescue_from ActionController::InvalidCrossOriginRequest do
unless Rails.application.config.consider_all_requests_local
render_404
end
end
end
end


Related Topics



Leave a reply



Submit