I think Rails 3.1 is changing the way that errors are raised. Can anyone assist or confirm this? I'm attempting to create custom errors pages with Rails 3.1.0.rc1
unless config.consider_all_requests_local
rescue_from Exception, :with => :render_error
rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
rescue_from ActionController::RoutingError, :with => :render_not_found
rescue_from ActionController::UnknownController, :with => :render_not_found
rescue_from ActionController::UnknownAction, :with => :render_not_found
end
^^ This doesn't work.
config.consider_all_requests_local = true
That is in my development environment by default. I'm assuming Rails 3.1 removes the "action_controller" but I can't confirm this anywhere.
Thanks!
I'm assuming the following code appears in your ApplicationController?
unless config.consider_all_requests_local
rescue_from Exception, :with => :render_error
rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
rescue_from ActionController::RoutingError, :with => :render_not_found
rescue_from ActionController::UnknownController, :with => :render_not_found
rescue_from ActionController::UnknownAction, :with => :render_not_found
end
If so, try replacing this line:
unless config.consider_all_requests_local
with this line (pre Rails 3 I think):
unless ActionController::Base.consider_all_requests_local
or this (post Rails 3):
unless Rails.application.config.consider_all_requests_local
I don't believe Matt's solution will catch routing errors in Rails 3.0/3.1.
Try putting the following in your application.rb:
# 404 catch all route
config.after_initialize do |app|
app.routes.append{ match '*a', :to => 'application#render_not_found' } unless config.consider_all_requests_local
end
See: https://github.com/rails/rails/issues/671#issuecomment-1780159
Worked well for me!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With