gpt4 book ai didi

ruby-on-rails - Rails 4 Assets 管道不会使用对其他 Assets 的 asset_path 引用覆盖 Assets

转载 作者:行者123 更新时间:2023-12-03 00:37:50 30 4
gpt4 key购买 nike

因此,我们在 Assets 管道摘要方面遇到了一个小问题,因为我们有许多 HTML 模板作为 Assets (对于 AngularJS),并且我们使用 asset_path 在 Javascript 文件中引用这些 Assets 的路径 helper 。不幸的是,由于 Assets 预编译步骤(和 Heroku)检查更改的方式,对模板进行更改不会导致 javascript 文件重新编译。

所以基本上在像 application.coffee.erb 这样的文件中,我们可能有类似的东西:

url = '<%= asset_path('views/template.html') %>'

当我们运行rake assets:precompile时,它将变成/assets/views/template-1023911231.html,它有一个摘要值,但如果 template.html.slim 更改后,摘要也会更改,但由于 application.coffee.erb 并未从根本上更改,因此不会重新编译,并继续指向旧摘要。

想法?解决方案?实际上,这对我来说似乎是一个错误。

更新

目前最好的解决方案是,如果我们需要更改 HTML 模板资源但没有任何 javascript 发生变化,则更新 application.rb 中的资源版本。

最佳答案

解决方案是 suggested here其中涉及使用 depend_ondepend_on_asset 指令。就我而言,将其添加到 .js.erb 文件中有效:

//= depend_on_asset views/template.html

url = '<%= asset_path('views/template.html') %>'

只要 views/template.html 根据需要进行更改,就会重新编译该文件。

关于ruby-on-rails - Rails 4 Assets 管道不会使用对其他 Assets 的 asset_path 引用覆盖 Assets ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19598992/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com