6
votes

I was running into issues with Heroku showing my 'places.js' was not precompiled, even though im running on the cedar stack, and during the slug compilation it is running the rake precompile task. so i tried running it locally with rake assets:precompile RAILS_ENV=production and indeed rails was not precompiling my /app/assets/javascripts/places.js.coffee.erb asset.

my production.rb is using default rails 3.1 configuration, and i even tried removing the .erb from the asset, but to no avail.

I also thought since my places.js.coffee.erb asset is NOT included in the sprockets manifest (i include it manually in my app), perhaps it only precompiles assets in the manifest. Requiring it in the manifest didn't work either.

only my application.js.coffee and `application.css are precompiling (with and without a digest).

the only issue i found was possibly poor regex being used to match assets, but the default of (?:\/|\\|\A)application\.(css|js)$ does not match my asset, so it should be included.

i am not sure how to troubleshoot from here. everything is pretty much default. any thoughts on what could be happening here?

3

3 Answers

10
votes

Firstly, if you want a file to compile when it is not in a manifest, you need to add it to the precompile config option:

config.assets.precompile += ['places.js']

Secondly, can you edit your question to include your manifest - it may be a syntax issue. I will edit this answer if I can see what the issue might be.

4
votes

I had the same issue and resolved it like this:

# add new file /app/assets/javascripts/places_manifest.js
//= require places

# add a line to config/application.rb
config.assets.precompile += ['places_manifest.js']

# in your views include places_manifest, not places
javascript_include_tag 'places_manifest'
1
votes

While the above solutions seem fine, I wondered why do I have to do this?

Like everyone else, I got the error in production stating that my newly added javascript file was not pre-compiled. It was however, I found it's code in the minified application.css file that Rails had generated on my production server.

The problem was that while developing, I thought I would need to add a javascript_include_tag helper to load my new javascript file. Adding that helper was the source of my particular error. I just removed it, and everything worked fine in both development and production environments.

So my suggestion to you is look for signs of your new .js file in your minified application.js and don't modify any other files as the above solutions suggest. Please point out the error in my ways if necessary ;)