Preventing broken images hitting Rails in development

447 Views Asked by At

Anyone know of a simple way to prevent broken images hitting Rails in development?

Sometimes I need to load the production database to debug a specific problem, and the broken images add noise to the logs and slows down Rails.

I'm using pow and am proxying https requests through nginx (on Mac OS X Lion).

[Update]

After upgrading to rails 3.1.3 and adding config.serve_static_assets = false to development.rb, the problem still exists.

Here's an example from the logs:

Started GET "/system/template_pics/images/000/000/043/original-254f3340aa9285267db373d8f479144e-1327358518/home6.jpeg" for 127.0.0.1 at Mon Feb 27 14:42:34 +1100 2012

ActionController::RoutingError (No route matches [GET] "/system/template_pics/images/000/000/043/original-254f3340aa9285267db373d8f479144e-1327358518/home6.jpeg"):
2

There are 2 best solutions below

1
On

Set rails to not serve static assets in config/development.rb:

config.serve_static_assets = false

Nginx should be setup to serve static assets itself, and any that don't exist won't be server by Rails.

0
On

I have a script that deals with updating the development database with a MySQL dump from production, and in it I make sure to zero out the Paperclip fields so that the regular missing.png is loaded on dev and there's no clutter in the logs. So for your template pics, you'd have something like:

update template_pics SET image_file_name=NULL, image_content_type=NULL, image_file_size=NULL, image_updated_at=NULL;

Make sure you have the style variants for your missing.png on development for this to be thorough.