Missing Image RoutingError = TOO SLOW

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.

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

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.


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?

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)

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