Rails 4资产管道不会使用asset_path对其他资产的引用来覆盖资产 [英] Rails 4 asset pipeline doesn't overwrite assets with asset_path references to other assets
问题描述
因此,我们在资产管道摘要方面存在一个小问题,因为我们有许多HTML模板作为资产(用于AngularJS),并且我们使用 asset_path
helper。不幸的是,由于资产预编译步骤(和Heroku)如何检查更改,因此对模板进行更改并不会导致重新编译JavaScript文件。
因此,基本上像 application.coffee.erb
这样的文件可能类似于:
url ='<%= asset_path('views / template.html')%>'
当我们运行 rake assets:precompile
时,它会变成 /assets/views/template-1023911231.html
which具有摘要值,但是如果 template.html.slim
发生更改,则摘要将更改,但自
想法?解决方案?实际上,这对我来说似乎是一个错误。
更新
目前我拥有的最佳解决方案是更新资产版本在application.rb中,如果我们需要更改我们的HTML模板资产,但没有一个javascript已经改变。 解决方案
在此处建议,其中涉及使用 depend_on
或 depend_on_asset
指令。在我的情况下,将此添加到 .js.erb
文件中工作:
// = depends_on_asset views / template.html
$ b url ='<%= asset_path('views / template.html')%>'
只要根据需要更改 views / template.html
,就会重新编译此文件。
So we have a small problem with asset pipeline digests in that we have a number of HTML templates as assets (for AngularJS) and we references the paths for these assets in a Javascript file with the asset_path
helper. Unfortunately because of how the asset precompile step (and Heroku) check for changes, making changes to a template does not cause the javascript file to be recompiled.
So basically in a file like application.coffee.erb
we might have something like:
url = '<%= asset_path('views/template.html') %>'
And when we run rake assets:precompile
that will get turned into /assets/views/template-1023911231.html
which has a digest value but if template.html.slim
is changed the digest will change but since application.coffee.erb
has not fundamentally changed it isn't recompiled and continues to point to the old digest.
Thoughts? Solutions? This seems like a bug to me actually.
Update
Currently the best solution I have is to update the asset version in application.rb if we need to change our HTML template assets but none of the javascript has changed.
A solution was suggested here which involves using the depend_on
or depend_on_asset
directive. In my case adding this to the .js.erb
file works:
//= depend_on_asset views/template.html
url = '<%= asset_path('views/template.html') %>'
This will recompile this file any time there is a change to views/template.html
as desired.
这篇关于Rails 4资产管道不会使用asset_path对其他资产的引用来覆盖资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!