# Missing Image RoutingError = TOO SLOW

**URL:** <https://www.ruby-forum.com/t/missing-image-routingerror-too-slow/158805>\
**Category:** Rails\
**Created:** [January 28, 2009, 7:28am UTC](https://www.ruby-forum.com/t/missing-image-routingerror-too-slow/158805 "2009-01-28T07:28:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 28, 2009, 7:28am UTC](https://www.ruby-forum.com/t/missing-image-routingerror-too-slow/158805/1 "2009-01-28T07:28:40Z")

</div>

My development setup gets its data from our production database, and  
this production database refers to a bunch of images that aren’t  
available on my local machine, thus when running development I get a  
large number of Rails RoutingErrors, which I don’t really mind.

What I _do_ mind is that catching every one of these errors takes  
about 2-4 seconds, even with my quad-core desktop. If I try to load a  
page with 5 missing images, it will probably be 20 seconds before I  
can visit another page.

Has anyone else experienced this and thought up a clever workaround?  
I had hoped that using

rescue\_from(ActionController::RoutingError) { |e| render :nothing =\>  
true }

in my application controller would fix it, but it just serves to make  
the exception not print out its text. It still takes the regular  
amount of time per image for the exception to be caught and ignored.

Thank you greatly for any insights into how I might improve this.  
Bill

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 30, 2009, 12:16am UTC](https://www.ruby-forum.com/t/missing-image-routingerror-too-slow/158805/2 "2009-01-30T00:16:01Z")

</div>

Ah, definitely thinking along the right lines… then I’d just have to  
figure out some way to determine if the file actually existed on the  
machine or not. Which could probably be done, if not super  
efficiently.

I’ll keep this in mind as a potential solution, thanks for your idea.  
If anyone else has any other ideas, I’d be open to those as well.

Thanks,  
Bill

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 28, 2009, 7:59am UTC](https://www.ruby-forum.com/t/missing-image-routingerror-too-slow/158805/3 "2009-01-28T07:59:05Z")

</div>

Write a helper that wraps image\_tag that checks to see whether you are  
on your production box. Iff you are on the production box, then  
image\_tag it is, otherwise, some placeholder image guaranteed to be  
local in your images dir.

Will that work?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 31, 2009, 1:27am UTC](https://www.ruby-forum.com/t/missing-image-routingerror-too-slow/158805/4 "2009-01-31T01:27:29Z")

</div>

Well, you only need to tell if the file exists if you care about that.  
In dev, you may not. Try something like:

def wrapped\_image\_tag(image\_name, options={})  
image\_name = ‘placeholder.png’ if `hostname` =~ /local/  
image\_tag(image\_name, options)  
end

You may wind up with a page of placeholder.png’s but it’ll be real  
quick.
