Comments on: Being a good little 404er http://www.sitepoint.com/blogs/2006/08/30/being-a-good-little-404er/ Mon, 08 Sep 2008 02:29:12 +0000 http://wordpress.org/?v=2.5 By: Raise Error404, don't render and return – The Pug Automatic http://www.sitepoint.com/blogs/2006/08/30/being-a-good-little-404er/#comment-766954 Raise Error404, don't render and return – The Pug Automatic Thu, 24 Jul 2008 19:58:07 +0000 http://www.sitepoint.com/blogs/?p=1698#comment-766954 [...] from actions when you want to trigger a 404 error (as described here). [...] […] from actions when you want to trigger a 404 error (as described here). […]

]]>
By: nicolas http://www.sitepoint.com/blogs/2006/08/30/being-a-good-little-404er/#comment-349920 nicolas Sat, 25 Aug 2007 10:00:47 +0000 http://www.sitepoint.com/blogs/?p=1698#comment-349920 ... i'm not so sure... ..that 404 is really adequate, after all "Page not found" is not the same as "Record not found". It may be ok in the case of a "show" action, but it can also occur in "update" and "destroy" actions where "Page not found" doesn't make any sense whatsoever. Think of a raise-condition where 2 people handling the same record and one person deletes the record and the other one trys to delete/update after and boom... This maybe a rare situation but still mixing "Page not found" and "Record not found" feels wrong to me. So where as the concept is a good one (putting the Rescue into the ApplicationController) the actual action taken seems to be the wrong one. … i’m not so sure…
..that 404 is really adequate, after all “Page not found” is not the same as “Record not found”.
It may be ok in the case of a “show” action, but it can also occur in “update” and “destroy” actions where “Page not found” doesn’t make any sense whatsoever.
Think of a raise-condition where 2 people handling the same record and one person deletes the record and the other one trys to delete/update after and boom…
This maybe a rare situation but still mixing “Page not found” and “Record not found” feels wrong to me.
So where as the concept is a good one (putting the Rescue into the ApplicationController) the actual action taken seems to be the wrong one.

]]>
By: Danger http://www.sitepoint.com/blogs/2006/08/30/being-a-good-little-404er/#comment-152001 Danger Fri, 12 Jan 2007 06:26:10 +0000 http://www.sitepoint.com/blogs/?p=1698#comment-152001 Rick Olson also has made use of the "save!" method through similar means. He's the only guy I've seen actually use save! (which raises an error if the save fails) and have his rescue_action catch it. Very slick. Rick Olson also has made use of the “save!” method through similar means. He’s the only guy I’ve seen actually use save! (which raises an error if the save fails) and have his rescue_action catch it. Very slick.

]]>
By: niko http://www.sitepoint.com/blogs/2006/08/30/being-a-good-little-404er/#comment-100380 niko Mon, 20 Nov 2006 15:27:15 +0000 http://www.sitepoint.com/blogs/?p=1698#comment-100380 OK. Got it. At the beginning of the controller_test stubs there is this line: # Re-raise errors caught by the controller. class PageController; def rescue_action(e) raise e end; end Of course i had to uncomment the redefinition of rescue_action to make the tests pass. Is there any bad side-effects in doing this? More cheers, Niko. :) OK. Got it. At the beginning of the controller_test stubs there is this line:

# Re-raise errors caught by the controller.
class PageController; def rescue_action(e) raise e end; end

Of course i had to uncomment the redefinition of rescue_action to make the tests pass. Is there any bad side-effects in doing this?

More cheers, Niko. :)

]]>
By: niko http://www.sitepoint.com/blogs/2006/08/30/being-a-good-little-404er/#comment-99558 niko Sun, 19 Nov 2006 17:22:07 +0000 http://www.sitepoint.com/blogs/?p=1698#comment-99558 Hm… little problem: although i used "rescue_action" and everything works in dev mode my tests fail: get :show, {:id=>42, :path=>"somepage.html"} assert_response 404 gives me: Couldn't find Page with ID=42 Any idea? Hm… little problem: although i used “rescue_action” and everything works in dev mode my tests fail:

get :show, {:id=>42, :path=>”somepage.html”}
assert_response 404

gives me:

Couldn’t find Page with ID=42

Any idea?

]]>
By: niko http://www.sitepoint.com/blogs/2006/08/30/being-a-good-little-404er/#comment-99531 niko Sun, 19 Nov 2006 16:20:53 +0000 http://www.sitepoint.com/blogs/?p=1698#comment-99531 And i was even using find(:first, :condition=>{… to make bogus find-operation _not_ raise an error but return false which i handled afterwards. Your method is so much more ellegant. Thank you, Tim. And i was even using find(:first, :condition=>{… to make bogus find-operation _not_ raise an error but return false which i handled afterwards. Your method is so much more ellegant. Thank you, Tim.

]]>
By: timlucas http://www.sitepoint.com/blogs/2006/08/30/being-a-good-little-404er/#comment-51517 timlucas Mon, 04 Sep 2006 14:12:28 +0000 http://www.sitepoint.com/blogs/?p=1698#comment-51517 I love it when that happens! Thanks for pointing out that rescue_action_in_public only happens in production. If you want to emulate it in dev you can define <code>rescue_action_locally</code> and call the other rescue, as follows: <pre><code> def rescue_action_locally(e); rescue_action_in_public(e); end </code></pre> I love it when that happens!

Thanks for pointing out that rescue_action_in_public only happens in production. If you want to emulate it in dev you can define rescue_action_locally and call the other rescue, as follows:


def rescue_action_locally(e); rescue_action_in_public(e); end
]]>
By: igrigorik http://www.sitepoint.com/blogs/2006/08/30/being-a-good-little-404er/#comment-50182 igrigorik Sat, 02 Sep 2006 03:29:11 +0000 http://www.sitepoint.com/blogs/?p=1698#comment-50182 It's brilliant! I must have been looking at the same code as you were because I found the article after I started 'googling' for more information on this technique. Anyway, just a little tip/pointer for anyone who is thinking of using this: - rescue_action_in_public is for requests answering false to local_request? (From the documentation). Meaning, if you're trying to test this on your local machine, it will still render the default exception template with RecordNotFound info on it. Seems obvious once you know it, but it took me solid 10 minutes to figure out why I 'didn't seem to work on my machine'. Replacing rescue_action_in_public with rescue_action will redirect/render on your local machine/dev environment also. Cheers, Ilya It’s brilliant! I must have been looking at the same code as you were because I found the article after I started ‘googling’ for more information on this technique.

Anyway, just a little tip/pointer for anyone who is thinking of using this:
- rescue_action_in_public is for requests answering false to local_request? (From the documentation). Meaning, if you’re trying to test this on your local machine, it will still render the default exception template with RecordNotFound info on it. Seems obvious once you know it, but it took me solid 10 minutes to figure out why I ‘didn’t seem to work on my machine’.

Replacing rescue_action_in_public with rescue_action will redirect/render on your local machine/dev environment also.

Cheers,
Ilya

]]>