Hoopla! » Rails: Custom 404 Pages

sasha said: there is another more generic way that will catch all the errors, you can inspect the exception to route to the right view, and possibly log the trace: in application.rb
def rescue_action_in_public(exception)
  # do something based on exception
  message = exception.backtrace.join("\n") unless exception
  render :file => "#{RAILS_ROOT}/public/404.html", :layout => false, :status => 404
end

def local_request?
  false
end
thanks for the CSV tip. doc is atrocious

覆寫「rescue_action_in_public」來處理 global 的 exception。

Catch-All routes in Rails | Floyd's Thoughts...

If that’s your last route, it means that anything that isn’t recognised by any of the other routes will get routed to that controller/action (page_engine/show_page). It shouldn’t interfere with images/assets because they are served with higher priority than Rails routes. It lets you have any number of forward-slashes.

如果是用 catch-all route,也就是擺在最後面的「*route」,是不會影響 asset 的東西。因為它們的 routing priority 比 routes.rb 裡面定義的還高。