I have some HTML and JS template files that are in the resource directory, structured as follows:
app
- assets
- templates
- my_template.html
- javascripts
- application.js
- main.js.erb
Where application.jscontains the standard asterisk directive://= require main
and main.js.erbcontains a link 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.erbevaluated as follows:
return {
pathToTemplate: "assets/my_template.html"
}
During the production process, the assets are precompiled (gzipped and whitespace deleted), and the fingerprint is added to the file name.
main.js.erb :
pathToTemplate: "assets/my_template-610dd79b5bb3c20d14b81baa891fc9dd.html"
, .
Sprockets HTML? , ,
, object_path main.js.erb?
.