Hey PDX,
I'm wondering if there was an easier way of testing custom 404 & 500
error pages during development. I've created the pages, and they work
during development, however I have to comment out
'Rails.application.config.consider_all_requests_local' from my
ApplicationController and routes.rb for them to work. My /environment/
development.rb is set with 'config.consider_all_requests_local =
true'.
Moreover, what is the recommended approach to writing an acceptance
test for these error pages?
---------
Here's my ApplicationController:
class ApplicationController < ActionController::Base
# ...
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: :render_500
rescue_from ActionController::RoutingError, with: :render_404
rescue_from ActionController::UnknownController, with: :render_404
rescue_from AbstractController::ActionNotFound, with: :render_404
rescue_from ActiveRecord::RecordNotFound, with: :render_404
end
private
def render_404(exception)
@not_found_path = exception.message
respond_to do |format|
format.html { render template: 'errors/error_404', layout:
'layouts/application', status: 404 }
format.all { render nothing: true, status: 404 }
end
end
def render_500(exception)
@error = exception
respond_to do |format|
format.html { render template: 'errors/error_500', layout:
'layouts/application', status: 500 }
format.all { render nothing: true, status: 500}
end
end
# ...
end
----------
Here's my routes.rb
unless Rails.application.config.consider_all_requests_local
match '*not_found', to: 'errors#error_404'
end
---------
Specifically, I'm following the guidance from this blog post.
http://ramblinglabs.com/blog/2012/01/rails-3-1-adding-custom-404-and-500-error-pages
Please let me know if I should clarify anything else.
Best,
Doug