Relative newb here.
Is there a relatively simple way to gracefully trap routing errors?
I seem to be in the same boat with a lot of other people ...
In application.rb I have
Relative newb here.
Is there a relatively simple way to gracefully trap routing errors?
I seem to be in the same boat with a lot of other people ...
In application.rb I have
Ralph Shnelvar wrote:
Relative newb here.
Is there a relatively simple way to gracefully trap routing errors?
I know this is not what you want to hear, but I consider returning the 404 page to be "graceful." That's what the HTTP 404 status code, and page, are for anyway. I would just customize the 404 page and be done with it.
Sorry I don't have a more direct answer to your specific question.
Robert Walker wrote:
Ralph Shnelvar wrote:
Relative newb here.
Is there a relatively simple way to gracefully trap routing errors?
I know this is not what you want to hear, but I consider returning the 404 page to be "graceful." That's what the HTTP 404 status code, and page, are for anyway. I would just customize the 404 page and be done with it.
Agreed. You should never get routing errors unless a user mistypes a URL -- and that's what the 404 page is for. That's all you need.
Sorry I don't have a more direct answer to your specific question.
That is a direct answer.
BTW: why the "#Shnelvar"? Aren't you using version control?
Best,
Marnen Laibow-Koser wrote:
BTW: why the "#Shnelvar"? Aren't you using version control?
My partner and I have not settle on a version control system to use yet.
Ralph Shnelvar wrote:
Marnen Laibow-Koser wrote:
BTW: why the "#Shnelvar"? Aren't you using version control?
My partner and I have not settle on a version control system to use yet.
I recommend Git, since distributed version control is the way to go; Mercurial might be a second choice. But pick one and use it. There is no excuse at all for working without version control even if you're a solo developer; with a partner, that's even more true. (Same for automated tests, BTW.)
Best,
OK ... so how do I get a 404 error instead of a
Routing Error
No route matches "/xxx" with {:method=>:get}
Ralph
Robert Walker wrote:
Marnen Laibow-Koser wrote:
Ralph Shnelvar wrote:
Marnen Laibow-Koser wrote:
BTW: why the "#Shnelvar"? Aren't you using version control?
My partner and I have not settle on a version control system to use yet.
I recommend Git, since distributed version control is the way to go; Mercurial might be a second choice. But pick one and use it. There is no excuse at all for working without version control even if you're a solo developer; with a partner, that's even more true. (Same for automated tests, BTW.)
Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org
My partner suggests SVN. Since we have not settled on anything yet ... and it seems to be either Git or SVN.
Ralph Shnelvar wrote:
OK ... so how do I get a 404 error instead of a
Routing Error
No route matches "/xxx" with {:method=>:get}
Stop fighting Rails! AFAIK, Rails already returns HTTP status 404 if it hits a RoutingError. You don't need to do anything else except customize 404.html.
Ralph
Best,
Ralph Shnelvar wrote:
My partner suggests SVN. Since we have not settled on anything yet ... and it seems to be either Git or SVN.
Use Git, then. SVN, as a centralized version control system, is far more limited than Git. It's a little easier to learn, but far less capable. Most Rails developers -- including me, as well as the core team -- left SVN for Git some time ago.
Best,
I am not fighting it.
I am getting a
Routing Error
No route matches "/xxx" with {:method=>:get}
rather than a 404 error during development.
So .. why am I getting that message instead of a 404 here?
Marnen Laibow-Koser wrote:
Ralph Shnelvar wrote:
I am not fighting it.
I am getting a
Routing Error
No route matches "/xxx" with {:method=>:get}
rather than a 404 error during development.
So .. why am I getting that message instead of a 404 here?
Because Rails handles errors differently in development and production. In development, you see diagnostic info; in production, you see 404.html. (I suspect the HTTP status code is 404 even in development, though; you could check with curl -i.)
And please don't top-post.
Best,
This is posted years after the fact, but just in case anyone arrives via a web search:
The rescue_from method shown above will NOT catch routing errors in Rails 3.1 and Rails 3.2. In particular, this won't work:
# file: app/controllers/application_controller.rb class ApplicationController < ActionController::Base protect_from_forgery rescue_from ActionController::RoutingError, :with => :not_found ...
You can read all about it (and suggested workarounds) here: https://github.com/rails/rails/issues/671 and here (point #3): My five favorite “hidden” features in Rails 3.2 « Plataformatec Blog
HTH.