I'm implementing dynamic error pages into an app, and have a feeling it's looking in the public
folder for (now non-existent) templates, rather than following the routes I've set up.
In config/application.rb
I've added the line config.exceptions_app = self.routes
to account for this.
I've then added the following to my routes:
get "/not-found", :to => "errors#not_found"
get "/unacceptable", :to => "errors#unacceptable"
get "/internal-error", :to => "errors#internal_error"
And the errors controller looks like so:
class ErrorsController < ApplicationController
layout 'errors'
def not_found
render :status => 404
end
def unacceptable
render :status => 422
end
def internal_error
render :status => 500
end
end
Going to /not-found
shows the template as it should be, though visiting any non-existing URL (i.e. /i-dont-exist) renders an empty page.
The only reason I could see for this would be that the exception handling needs the routes to be, for example, get "/404", :to => "errors#not_found"
, though, ironically, it's not finding the route for /404 (and no, that's not just it working :) ).
Any advice, greatly appreciated. Thanks, Steve.