2
votes

I've got some template HTML and JS files which are in the assets directory, structured like this:

app
 - assets
   - templates 
     - my_template.html
   - javascripts
     - application.js
     - main.js.erb

Where application.js contains the standard sprockets directive: //= require main

and main.js.erb contains a reference to the path for my_template.html: main.js.erb: // Some code here ... return { pathToTemplate: "<%= asset_path 'my_template.html' %>" } // More code here ...

In development, this works great. main.js.erb is evaluated to the following:

// Some code here ...
return {
    pathToTemplate: "assets/my_template.html"
}
// More code here

In production, assets are precompiled (gzipped and whitespace removed), and a fingerprint is appended to the filename.

Production main.js.erb should look like:

pathToTemplate: "assets/my_template-610dd79b5bb3c20d14b81baa891fc9dd.html"

but is instead the same as in development.

Does Sprockets need to be configured to also fingerprint HTML files? Perhaps it's a bug, because it's generating a manifest file with fingerprinted paths, but asset_path is returning a non-fingerprinted path in main.js.erb?

Thanks for your help.

2

2 Answers

2
votes

Sprockets itself no longer implements asset_path - this is a Rails helper provided by Action View.

https://github.com/rails/rails/blob/cd0b6233ae22f6bc8407d240eb2f933ca122f86d/actionpack/lib/action_view/helpers/asset_url_helper.rb#L120

This question should answer the rest of it for you:

Ruby on Rails 4 and usage of asset_path

0
votes

I've found that if I take all of the folders in the templates directory, and place them in the assets/images folder, then asset_path works as expected and returns fingerprinted paths. I expect this is a Rails bug.