Rails 3.1 some assets not precompiled in production

I ran into problems with Heroku, showing that my "places.js" was not precompiled, although im works on the cedar stack, and during slug compilation it starts the task of pre-breaking the rake. so I tried to run it locally using rake assets:precompile RAILS_ENV=production , and indeed, the rails did not precompile my resource /app/assets/javascripts/places.js.coffee.erb .

my production.rb uses the default rails 3.1 configuration, and I even tried to remove .erb from the asset, but to no avail.

I also thought that since my places.js.coffee.erb resource is NOT included in the sprockets manifest (I manually include it in my application), it may only precompile the assets in the manifest. Requiring this in the manifest did not work either.

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

The only problem I discovered is maybe a bad regex used to match assets, but the default value (?:\/|\\|\A)application\.(css|js)$ does not match my asset therefore it should be included.

I am not sure how to fix the problem here. all pretty much the default. any thoughts on what could be happening here?

+6
source share
3 answers

First, if you want the file to compile when it is not in the manifest, you need to add it to the precompile configuration option:

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

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

+10
source

I had the same problem and solved 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' 
+4
source

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

Like everyone else, I got a production error saying that my recently added javascript file was not precompiled. However, I found the code in the minified application.css file that Rails created on my production server.

The problem was that during development, I thought I needed to add the javascript_include_tag helper to load my new javascript file. Adding this helper was the source of my specific error. I just deleted it, and everything worked fine both in the development environment and in the production environment.

So, my suggestion for you is to look for signs of your new .js file in your minified application.js and not modify any other files, as the above solutions suggest. If necessary, indicate an error, if necessary;)

+1
source

Source: https://habr.com/ru/post/901688/


All Articles