# Missing images cause routing errors?

**URL:** <https://www.ruby-forum.com/t/missing-images-cause-routing-errors/134953>\
**Category:** Rails\
**Created:** [April 16, 2008, 3:57pm UTC](https://www.ruby-forum.com/t/missing-images-cause-routing-errors/134953 "2008-04-16T15:57:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuval](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/977dab/32.png) [@Yuval](https://www.ruby-forum.com/u/Yuval)\
**Post date:** [April 16, 2008, 3:57pm UTC](https://www.ruby-forum.com/t/missing-images-cause-routing-errors/134953/1 "2008-04-16T15:57:41Z")

</div>

Dear folks. I recently discovered that I get nasty RoutingError  
exceptions any time I refer to an image that doesn’t exist (whether I  
use an html img tag or an image\_tag helper). Now obviously, I  
shouldn’t be pointing to missing images, but it’s going to happen on  
occasion. As far as I could tell from the helper documentation, Rails  
doesn’t confirm the existence of assets before linking to them, so I  
didn’t expect such an ungracious bombing in the case of missing  
images. Are there underlying routes that handle the loading of images,  
that can perhaps be suppressed in the case of missing files? Does  
anyone have any input on this? Cheers.

---

<div class="post-metadata">

**Author:** ![Yuval](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/977dab/32.png) [@Yuval](https://www.ruby-forum.com/u/Yuval)\
**Post date:** [April 16, 2008, 6:04pm UTC](https://www.ruby-forum.com/t/missing-images-cause-routing-errors/134953/2 "2008-04-16T18:04:13Z")

</div>

On Apr 16, 9:57 am, Yuval [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Dear folks. I recently discovered that I get nasty RoutingError  
> exceptions any time I refer to an image that doesn’t exist (whether I  
> use an html img tag or an image\_tag helper). Now obviously, I  
> shouldn’t be pointing to missing images, but it’s going to happen on  
> occasion. As far as I could tell from the helper documentation, Rails  
> doesn’t confirm the existence of assets before linking to them, so I  
> didn’t expect such an ungracious bombing in the case of missing  
> images. Are there underlying routes that handle the loading of images,  
> that can perhaps be suppressed in the case of missing files? Does  
> anyone have any input on this? Cheers.

You can modify your routes.rb so that if Apache can’t find the image,  
routes it to rails, and of course the route isn’t in any controllers,  
to return some “Image not Found” gif via a method in application.rb.  
Especially if you have a consistent directory where you keep all those  
images, you can make this route very specific, and still catch “real”  
routing errors.
