3

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"):
Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Zubin
  • 9,422
  • 7
  • 48
  • 52
  • 1
    looking at the names these are not assets – Ben Feb 27 '12 at 03:51
  • 1
    True, they're paperclip uploads. – Zubin Feb 28 '12 at 08:40
  • 1
    maybe set up a rsync to get the images, I dont think you can disable paperclip on development. Mind you, this has NOTHING to do with the asset pipeline. – Ben Feb 28 '12 at 11:09
  • Maybe you should setup a rsync script to sync with your production environment. You cannot disable this, and it definately doesnt go trough the asset pipeline – Ben Feb 28 '12 at 14:05
  • Good suggestion @BenjaminUdinktenCate; I've done that on other projects but this one has tens of thousands of images stored on S3 so it's not practical to rsync them all. – Zubin Feb 29 '12 at 21:20

2 Answers2

0

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.

tirdadc
  • 4,603
  • 3
  • 38
  • 45
0

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.

Douglas F Shearer
  • 25,952
  • 2
  • 48
  • 48
  • Thanks, but adding that and restarting didn't seem to have any effect - the log file still shows routing errors from broken images. Btw it's a rails 3.0.10 app. – Zubin Oct 26 '11 at 21:54