资产显示“未预编译”当它们被预编译时

发布于 2024-12-07 17:52:46 字数 2216 浏览 2 评论 0原文

好的,当我尝试使用资产管道时,我收到此错误。我不明白是什么原因造成的。

Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Photos#show

Showing .../app/views/photos/_photo_view.html.haml where line #2 raised:

jquery.autocomplete isn't precompiled

Extracted source (around line #2):

1: - content_for :scripts do
2:  = javascript_include_tag 'jquery.autocomplete'

然而,这是预编译的。我在启动服务器之前运行了rake assets:precompile RAILS_ENV=product,在我的public/assets目录中,我有文件:jquery-5550a245a55b28927b5552cac182e612.autocomplete.js 以及 .js.gz,并且它准确地反映在清单中:

#manifest.yml
---
application.js: application-4277323e3f7506b71f45c71e8a3a7c8f.js
jquery.autocomplete.js: jquery-5550a245a55b28927b5552cac182e612.autocomplete.js
jquery.cycle.all.min.js: jquery-183ef696b43944deaee5778d3094dbdd.cycle.all.min.js
jquery.fancybox.js: jquery-e52e44b2b4fb349bade9beb91461a810.fancybox.js
jquery.plupload.queue.js: jquery-f2e7f6ad7d2e5ca50235ed21f8d573cc.plupload.queue.js
jquery.tools.js: jquery-c53e304240fa56767fe0f2a00cb4bceb.tools.js
plupload.full.js: plupload-5dd26ee3fff6b627c19f196e9d1429dd.full.js
application.css: application-ce5217e1714cbc4e9c3ff6c5dfc9b221.css
fancybox.css: fancybox-9ee9c36f391086e4b0629b7df4042390.css
jquery.plupload.queue.css: jquery-661fbf3f503aa32ff11c004838c0820b.plupload.queue.css
jquery.js: jquery-4d23f0cfea862f56deb04f0a8ab1fcee.js
jquery.min.js: jquery-8a50feed8d29566738ad005e19fe1c2d.min.js

有问题的 javascript 文件未加载到我的 application.js 文件中,因为我只在一个视图上需要它,并且不在应用程序的其他任何地方使用它。为了解决这个问题(并修复尝试编译 sass 部分的链轮),我像这样配置了预编译正则表达式:(

#environments/production.rb
config.assets.precompile = [/^[a-zA-Z]*\..*/]

上面的正则表达式预编译以字母字符开头的任何文件,并忽略以非字母字符(如下划线)开头的文件)。

有谁知道造成这种情况的原因以及如何解决它?资产管道让我抓狂!

更新

刚刚发现 Rails.configuration.assets.digests 在生产中返回 nil 。也许问题就在那里,由于某种原因链轮找不到manifest.yml。

我可能错了,但看起来链轮在查找manifest.yml时没有在配置中使用assets_host。

https://github.com /rails/rails/blob/3-2-stable/actionpack/lib/sprockets/railtie.rb#L38

Ok so, I'm getting this error when I try to use the asset pipeline. I don't understand what's causing it.

Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Photos#show

Showing .../app/views/photos/_photo_view.html.haml where line #2 raised:

jquery.autocomplete isn't precompiled

Extracted source (around line #2):

1: - content_for :scripts do
2:  = javascript_include_tag 'jquery.autocomplete'

However, this IS precompiled. I ran rake assets:precompile RAILS_ENV=production before starting the server, and in my public/assets directory I have the file: jquery-5550a245a55b28927b5552cac182e612.autocomplete.js as well as .js.gz, and it's accurately reflected in the manifest:

#manifest.yml
---
application.js: application-4277323e3f7506b71f45c71e8a3a7c8f.js
jquery.autocomplete.js: jquery-5550a245a55b28927b5552cac182e612.autocomplete.js
jquery.cycle.all.min.js: jquery-183ef696b43944deaee5778d3094dbdd.cycle.all.min.js
jquery.fancybox.js: jquery-e52e44b2b4fb349bade9beb91461a810.fancybox.js
jquery.plupload.queue.js: jquery-f2e7f6ad7d2e5ca50235ed21f8d573cc.plupload.queue.js
jquery.tools.js: jquery-c53e304240fa56767fe0f2a00cb4bceb.tools.js
plupload.full.js: plupload-5dd26ee3fff6b627c19f196e9d1429dd.full.js
application.css: application-ce5217e1714cbc4e9c3ff6c5dfc9b221.css
fancybox.css: fancybox-9ee9c36f391086e4b0629b7df4042390.css
jquery.plupload.queue.css: jquery-661fbf3f503aa32ff11c004838c0820b.plupload.queue.css
jquery.js: jquery-4d23f0cfea862f56deb04f0a8ab1fcee.js
jquery.min.js: jquery-8a50feed8d29566738ad005e19fe1c2d.min.js

The javascript file in question is not loaded in my application.js file because I only need it on one view and don't use it anywhere else in the app. To account for that (and to fix sprockets trying to compile sass partials) I configured my precompile regexp like so:

#environments/production.rb
config.assets.precompile = [/^[a-zA-Z]*\..*/]

(The above regexp precompiles any file that starts with a letter character, and ignores files starting with a non-letter character like an underscore).

Does anyone have any insight into what's causing this and how it can be fixed? The asset pipeline is making me pull my hair out!

UPDATE

just found out that Rails.configuration.assets.digests is returning nil in production. maybe the problem is there, for some reason sprockets is not finding the manifest.yml.

Im probably mistaken but seems like sprockets is not using the assets_host in config when looking for the manifest.yml.

https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/sprockets/railtie.rb#L38

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柏拉图鍀咏恒 2024-12-14 17:52:46

.js 添加到

javascript_include_tag 'jquery.autocomplete.js'

似乎缺少功能。当文件名包含句点“.”时在名称中,在查看摘要时不会添加 .js 扩展名。

我对 Sprockets::Helpers::RailsHelper 进行了一些调试,似乎 digest_for 方法获取了没有 .js 的逻辑路径。

Add the .js to

javascript_include_tag 'jquery.autocomplete.js'

Seems like there is an missing functionality. When the filename has a period '.' in the name, the .js extension will not get added when looking into the digest.

I did some debugging to Sprockets::Helpers::RailsHelper and it seems like digest_for methods gets the logical path without the .js.

梦里人 2024-12-14 17:52:46

我自己一直在努力解决这个问题,尽管设置了 config.assets.compile = false,因为我怀疑上面的示例将标志设置为 true。

无法通过以下方式配置资产本地生产 Rails 3.1.3 服务器上的管道

我的观察结果是它是一个 Sprockets 2.0.3 错误,正如 UberNeet 所建议的那样。解决方法是从资产名称中删除句点,或者将其包含在清单中,而不是直接链接到它。

错误报告在这里:https://github.com/rails/rails/issues/ 3398

看看上面的问题,并结合我过去两天的经验,我怀疑设置 config.assets.compile = true 时资产命名存在相关问题。这个问题可能源于资产命名 - 您的清单将 jquery.autocomplete 库预编译为:

jquery-5550a245a55b28927b5552cac182e612.autocomplete.js

但是当您使用 rake asset:precompile 通过 rake 预编译这些资产时,我相信它们实际上被编译为

jquery.autocomplete-5550a245a55b28927b5552cac182e612.js

:可能正是这种差异导致了您提到的问题。可能也值得为此提出另一个 github 问题,尽管上面列出了解决方法,并且我知道 Rails 3.2 将使用 Sprockets 2.1.0,其中可能已经包含此问题的修复程序。

I have been wrestling with the problem myself, although with config.assets.compile = false set, as I suspect the example above was with the flag set to true.

Cannot configure assets via pipeline on local production rails 3.1.3 server

My observations came down to it being a Sprockets 2.0.3 bug, as UberNeet suggested towards. The workaround was to either remove the period from the asset name, or include it as part of a manifest, rather than link to it directly.

The bug report for this is here: https://github.com/rails/rails/issues/3398

Looking at your issue above, and tallying it with my experience from the last two days, I suspect there is an associated issue with asset naming when config.assets.compile = true is set. This issue probably stems from the asset naming - your manifest has the jquery.autocomplete library percompiled as:

jquery-5550a245a55b28927b5552cac182e612.autocomplete.js

But when you precompile these assets via rake using rake assets:precompile, I believe they are actually compiled to:

jquery.autocomplete-5550a245a55b28927b5552cac182e612.js

It is probably this discrepancy that is causing the issue you mentioned. Might be worth raising another github issue for this too, although the workarounds are listed above, and I understand that Rails 3.2 will be using Sprockets 2.1.0, which may contain the fix for this issue already.

花落人断肠 2024-12-14 17:52:46

请确保之前在 application.js 中不需要它。

Be shure that it isn't required before in application.js for example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文