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

hunteros

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

I am quite certain that this is purely a Asset Pipeline question, but to give you a complete sense of our tech stack: We use Rails 4.0, Ruby 2.1, AngularJS for our front-end MVC framework, and AssetSync to synchronize our assets between Rails and our CDN.

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

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

This works great locally, but as soon as config.assets.digest = true in production, the call to asset_path does not properly factor in the fingerprint. The templates are in the app/assets directory within a new subdirectory templates. So in the above example, the home.html asset is at app/assets/templates/home.html. Our javascript has itself been precompiled at that point, so I'm thinking that it might be an issue of which order the assets are precompiled in.

I've noticed a few issues on the Rails Github (1, 2, 3) and a couple of SO posts about fingerprints not being set properly (1, 2), but can't find anything about them not being included at all...

Any help or ideas that you can provide would be much appreciated.

Edit 4/15: forgot to include that the extensions on my application javascript file DOES include .erb (app/assets/application.js.erb). Thanks Alex for catching that. I've updated it above. Also, following instructions in this article on Heroku, I confirmed that running puts helper.asset_path("home.html") from within a Rails console running in production prints a properly fingerprinted URL for that asset.

hunteros

This appears to be an issue with the AssetSync gem. I removed it, reconfigured the app so that Rails serves the assets, and the fingerprinting works fine.

If anyone else finds this question and is running into the same issue, I would recommend against 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 method of serving assets through a CDN, and is very easy to configure with a Rails app that serves its own static assets, accomplishing the same goals as AssetSync.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Rails 4 asset pipeline doesn't overwrite assets with asset_path references to other assets

From Dev

Rails 4: undefined method `asset_path'

From Dev

Ruby on Rails 4 and usage of asset_path

From Dev

Rails 4 Asset Pipeline: Compile both with and without fingerprint

From Dev

duplicate Rails 4 asset fingerprint file on Heroku

From Dev

asset_path in rails console on heroku for images

From Dev

Rails 4 asset or image path from CSS

From Dev

Prevent Rails 4 Sprocket Asset Pipeline from caching a specific file

From Dev

rails 4 asset pipeline image subdirectories

From Dev

Rails 4 asset pipeline losing vendor assets

From Dev

Syntax of IF statement Rails 4 with Asset Pipeline

From Dev

Rails asset pipeline - custom js files

From Dev

Rails Asset Pipeline - How to determine if an asset exists?

From Dev

The asset ' ' is not present in the asset pipeline

From Dev

Handlebars + Images in Rails 4 - How do I get the right asset_path?

From Dev

Rails 4, Asset Compiling

From Java

Using fonts with Rails asset pipeline

From Dev

Rails asset pipeline: fonts not found

From Dev

Integrate Grunt into Rails asset pipeline

From Dev

Rails Asset Pipeline - Not compiling manifest

From Dev

Using libsass with Rails asset pipeline

From Dev

Using Asset Pipeline in Rails View

From Dev

Rails 3.2.13 Javascript Asset Pipeline

From Dev

Integrate Grunt into Rails asset pipeline

From Dev

Using Asset Pipeline in Rails View

From Dev

Inline CSS from the asset pipeline

From Dev

What are best practices organizing css for the Asset Pipeline in Rails 4

From Dev

Static 404 page Rails 4: how to use the asset pipeline?

From Dev

How to reset Heroku Rails4 asset pipeline cache

Related Related

HotTag

Archive