3

This question is similar to Why do I get “no route matches” for requests to the asset pipeline?.

I have a rails 3.0 application that I upgraded to 3.1 and converted to use the new asset pipeline (thanks to RailsCasts #282 and #279).

In production mode, I'm seeing the application-<digest>.js and application-<digest>.css. Great! And if I look at the source of those files, I see they are compressed. Yee-haw! So that means the asset pipeline is working, right?

However, if I add ?debug_assets=1 to the URL so that I may view individual files, some of them are producing ActionController::RoutingError (No route matches [GET] "/assets/<filename>-<digest>.js"), and same goes for some CSS files. But not all, just some, and I can't figure out what makes some files do this and others not.

I've cleared out tmp/cache/* and restarted Passenger. I've bumped config.assets.version. I've restarted memcached. None of these seem to resolve it. But what's odd is this only comes up when I'm using ?debug_assets=1 in the URL; without it, I see just one JS and CSS file, all compressed and minified.

I don't use precompiled assets, by the way. But just for grins, I performed a rake assets:precompiled, and whaddya know? The ?debug_assets=1 now shows all JS and CSS files, and none of them are 404'd.

So I guess the question you might have is, "Why not just use precompiled assets and not worry about missing assets from lazy load?" Good point. Answer: I just like to make sure I understand what I am doing, what's happening, and that I'm doing things correctly.

application.rb:

config.assets.enabled = true
config.assets.version = '1.2'

production.rb:

config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
config.assets.js_compressor  = :uglifier
config.assets.css_compressor = :scss

development.rb:

config.assets.compress = false

# I keep this off during development because I want
# to make sure the compression isn't breaking my JS
config.assets.debug = false 
Community
  • 1
  • 1
Matthew Clark
  • 1,885
  • 21
  • 32

1 Answers1

2

If you precompile your assets and set compile to false, debug is disabled because you've told Rails to not use Sprockets at all, but assumes that the files can be served by nginx based on mappings in the asset pipeline manifest.

When compile is true (like you have) then requests for these assets (and the debug request) are sent back to Sprockets to be processed if the files are missing (which without being precompiled is the case).

I would have assumed Sprockets would serve the individual files for each digested name. This behavior sounds buggy to me, although I don't think it is intended to use debug in production anyway.

Richard Hulse
  • 10,383
  • 2
  • 33
  • 37
  • You're right: shouldn't need this in production. I don't use IE (dev machine is Mac and app works perfectly in standards-compliant browsers), but all users of production app use IE 7, 8, & 9, sometimes it's helpful to add the `debug_assets` just to have a quick look or get an accurate line number of a CSS or JS file. Sux that it's not dependable in production mode. – Matthew Clark Oct 10 '11 at 21:59