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
Gem Install Permission Problem
How to Get Request Referer Path
Installing Jekyll Without Root
What Does Class_Eval ≪≪-"End_Eval", _File_, _Line_ Mean in Ruby
Getaddrinfo: Nodename Nor Servname Provided, or Not Known
Rails Engines Extending Functionality
Why Would One Use the Unary Operator on a Property in Ruby? I.E &:First
Ruby - Share Logger Instance Among Module/Classes
Converting an Array of Objects to Activerecord::Relation
In Ruby, How Does Coerce() Actually Work
How to Avoid Nomethoderror For Nil Elements When Accessing Nested Hashes
Converting String from Snake_Case to Camelcase in Ruby
Why Isn't Self Always Needed in Ruby/Rails/Activerecord
How to Run All Tests With Minitest
Read and Write Yaml Files Without Destroying Anchors and Aliases