Rails 4 Asset Pipeline: Asset missing fingerprint in path_path from js

I am deploying a Rails 4.0 application that includes partial HTML templates as assets for our javascript front-end infrastructure. Although these templates are part of the asset pipeline and properly precompiled when I call asset_path from the built-in ruby ​​in our js files, it returns the path to our templates without a fingerprint.

I am quite sure that this is a question exclusively for Asset Pipeline, but in order to give you a complete picture of our technical stack: we use Rails 4.0, Ruby 2.1, AngularJS for our front-end MVC structure and AssetSync to synchronize our resources between Rails and our CDN.

An example of where this happens (in the file included in app/assets/application.js.erb :

 $routeProvider .when('/', { templateUrl: "<%= asset_path 'home.html' %>", controller: "HomeController" }); 

This works fine in place, but as soon as config.assets.digest = true during production, the asset_path call asset_path not affect the fingerprint. The templates are located in the app/assets directory in the new templates subdirectory. So, in the above example, the home.html resource is in app/assets/templates/home.html . Our javascript itself was precompiled at this point, so I think it might be a problem of what order of assets is precompiled.

I noticed a few problems in Rails Github ( 1 , 2 , 3 ) and a few SO messages saying that fingerprints are not installed properly ( 1 , 2 ), but cannot find anything that they don't turn on at all ...

Any help or ideas you can provide would be greatly appreciated.

Edit 4/15 : forgot to include that extensions in the javascript file of my application include .erb ( app/assets/application.js.erb ). Thanks Alex for that. I updated it above. In addition, following the instructions in this article about Heroku , I confirmed that running puts helper.asset_path("home.html") from the Rails console launched during production prints the correctly typed URL for this asset.

+3
source share
2 answers

This is apparently a problem with AssetSync . I uninstalled it, reconfigured the application so that Rails serves the assets, and the fingerprint works fine.

If someone else finds this question and encounters the same problem, I would recommend not using AssetSync. According to Heroku :

 Many developers make use of Amazon's S3 service for serving static assets that have been uploaded previously, either manually or by some form of build process. Whilst this works, this is not recommended as S3 was designed as a file storage service and not for optimal delivery of files under load. Therefore, serving static assets from S3 is not recommended. 

Amazon CloudFront is the preferred way to service assets via CDN, and it is very easy to configure using the Rails application, which serves its own static assets, achieving the same goals as AssetSync.

+1
source

I'm new to this, but in order to get resource_path to work you don't need .erb at the end of this file?

Look at the bottom of this article for more information:

https://devcenter.heroku.com/articles/rails-4-asset-pipeline

If he works in development, this may not help. However, there is a useful debugging section at the bottom of the article.

Update

Here is another article that might help:

https://medium.com/self-directed-learning/9ba1f595102a

Having turned this configuration over to Heroku, some problems with the pipeline of my resource disappeared:

 heroku labs:enable user-env-compile -a yourapp 

Hope this helps!

Alex

0
source

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


All Articles