3

Question:

How do you get the asset pipeline to process all your .js files? (I want them served individually, not bundled into application.js)

I'm getting a ton of 404's for the javascript files that my pages are trying to reference:

GET http://<myStagingServer>.heroku.com/assets/<javascriptFilename1_MD5fingerprint> 404 (Not Found)
GET http://<myStagingServer>.heroku.com/assets/<SubDir>/<javascriptFilename2_MD5fingerprint> 404 (Not Found)

I tried adding this to config/application.rb:

config.assets.precompile << '*.js'

But that didn't do anything as far as I can tell.

Background:

I'm upgrading from Rails 3.0 to 3.1 and enabling the asset pipeline.

Highlights so far:

  • Switching to Heroku's Cedar stack from Bamboo: heroku create --stack cedar.
  • Switching to "thin" as the production server, which fixed various issues: gem 'thin'.
  • Moving my assets from public/assets to app/assets, updating references in code to use stylesheet_link_tag and javascript_include_tag. (Plus whatever I did for images -- they work.)
  • Removing x_sendfile_header config options because Heroku doesn't support it.

Relevant files:

//  
// application.js  
//  
//= require_self  
//  
Community
  • 1
  • 1
thewillcole
  • 2,943
  • 3
  • 30
  • 35
  • I don't know what compiling means for .js and .css. I think I'm going to learn something here. – duffymo Feb 19 '12 at 03:37
  • Show us your application.js/css – Sergio Tulentsev Feb 19 '12 at 03:40
  • @duffymo: Heh -- I only mean that I want them to be picked-up by Sprockets (I think), given and MD5 fingerprint, and then moved to the appropriate folder. – thewillcole Feb 19 '12 at 03:43
  • I think I'd rephrase my question, unless this is common usage of that word by Rails afficionadoes. – duffymo Feb 19 '12 at 03:45
  • @SergioTulentsev, I just noticed that I had been using "require_tree ." instead of "require_self" in application.js, so I changed it. Now my development environment works, but I'm still getting errors on staging/production. – thewillcole Feb 19 '12 at 04:00
  • Better, I guess. You'll find out from the responses you get. – duffymo Feb 19 '12 at 04:09

2 Answers2

4

OMG: I found the problem:

javascripts and stylesheets with periods in their names require explicit extensions

For example:

# WORKS
javascript_include_tag "application"
stylesheet_link_tag "application"

# BROKEN
javascript_include_tag "jueryui.custom"
stylesheet_link_tag "jueryui.custom"

# WORKS
javascript_include_tag "jueryui.custom.js"
stylesheet_link_tag "jueryui.custom.css"

I guess I can see why this is, but I think that it isn't very well documented on any of the asset pipeline tutorials. Is it common knowledge that you shouldn't have periods in your asset filenames?

Community
  • 1
  • 1
thewillcole
  • 2,943
  • 3
  • 30
  • 35
0

I think you need the following in both application.js and application.css :

//= require_tree .

This loads all the files in the assets directory for CSS and JS.

Also for upgrading to 3.1 and info on the asset pipeline:

http://railscasts.com/episodes?utf8=✓&search=Asset+pipeline

Also: Using Rails 3.1 assets pipeline to conditionally use certain css

Community
  • 1
  • 1
fatfrog
  • 2,118
  • 1
  • 23
  • 46
  • Thanks, but I'm trying to copy the files over individually -- not bundle them into the application asset file. You have pointed out the correct way to do the latter. – thewillcole Feb 25 '12 at 11:23