I am trying to setup a custom error page in my website. I am following the guidelines atPerfectLine Blog.
It works in the case where the controller exists, but the
You can do that with route globbing in rails, It lets you match any action to any part of a route using wildcards.
To catch all remaining routes, just define a low priority route mapping as the last route in config/routes.rb
:
In Rails 3:
match "*path" => 'error#handle404'
In Rails 2:
map.connect "*path", :controller => 'error', :action => 'handle404'
params[:path]
will contain the matching part.
If you don't need dynamic error pages, just edit public/404.html
and public/505.html
. If you do, see Reza.mp's answer.