Rails 3.1 资产在生产中被指纹识别,但渲染的 HTML 未被识别
开发中一切都运转良好。应用程序可以通过 Capistrano 正常部署。资产(javascript 和 css)似乎是完全预编译的,每个资产以及图像都被赋予了“指纹”。问题是,在我看来,使用 image_tag("image-name.png")
时,它在生产中创建的 html 不包含“指纹”。
我们在生产中得到的渲染 HTML:
<img alt="Image-name" src="/assets/image-name.png" />
而不是我所期望的,应该是:
<img alt="Image-name" src="/assets/image-name-b89cae2830c2901f844c353b3f3942fe.png" />
那么我们搞砸了 Rails 3.1 的无数配置选项中的哪一个?
编辑
图像似乎是我们使用的第三方 Colorbox 图像查看工具中包含的图像。 Rails 3.1 正在对其资产(border.png 等)进行指纹识别,但显然,此 javascript 库的源代码不使用像 image_tag
这样的帮助程序。因此在生产中它仍在寻找名为 /assets/colorbox/border.png
的图像。目前图像位于 /vendor/assets/images 中,并且在开发中工作正常。 有没有办法防止这些图像被“指纹识别”?
Everything works great in Development. And app deploys as normal with Capistrano. Assets (javascript & css) appear to be fully pre-compiled and each, along with images, are given a "fingerprint". Problem is when using image_tag("image-name.png")
in my view the html it creates in production doesn't include the 'fingerprint'.
The rendered HTML we get in production:
<img alt="Image-name" src="/assets/image-name.png" />
instead of, what I would expect, should be:
<img alt="Image-name" src="/assets/image-name-b89cae2830c2901f844c353b3f3942fe.png" />
So which of Rails 3.1's myriad config options did we botch?
Edit
The troublesome images appear to be those included in a 3rd-party Colorbox image viewing tool we use. Rails 3.1 is fingerprinting its assets (border.png, etc.) but, clearly, the source code for this javascript library doesn't use helpers like image_tag
. So in production it is still looking for images named /assets/colorbox/border.png
. Currently images are in /vendor/assets/images and work fine in Development. Is there a way to prevent just these images from being "fingerprinted"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,以下是我如何破解第 3 方文件以使其正常工作的方法:
有问题的图像位于
vendor/assets/stylesheets/colorbox.css
之类的文件中。我首先将文件的扩展名更改为.scss
,然后将每个url(colorbox/image.png)
更改为image_url("color box/image.png ")
现在一切都很顺利了。资产在开发中正常运行,并在生产中进行指纹识别。仍然希望看到添加第 3 方(供应商)javascript 库和的“正确”方法。 CSS 到 Rails 3.1 应用程序。 Rails 团队一定已经预料到了一个不需要编辑的直接解决方案?!?因此,请随意提供其他解决方案。
旁白:我之前手动配置了我的 Capistrano 配方:
...及其随附的
after deploy:update_code ...
。我现在已删除这些行,并将load 'deploy/assets
添加到我的Capfile
中。我认为这对上述问题没有任何影响,但无论如何我想记录下来,因为在 Capistrano 2.8 中不再需要像 3.1rc 那样添加自己的管道预编译配方。Well, here's how I hacked the 3rd-party files to make things work:
The offending images were in files like
vendor/assets/stylesheets/colorbox.css
. I first changed the extension of the files to.scss
then I changed eachurl(colorbox/image.png)
toimage_url("color box/image.png")
and now everything is peachy. Assets are served normally in development and fingerprinted in production.Still like to see the "proper" way to add 3rd-party (vendor) javascript libraries & css to a Rails 3.1 app. Rails team must have anticipate a drop-in solution that doesn't require editing?!? So, please, feel free to offer up other solutions.
Aside: where I previously had manually configured my Capistrano recipe with:
…and its accompanying
after deploy:update_code …
. I have now removed those lines and instead addedload 'deploy/assets
to myCapfile
. I don't think this makes any difference in the above problem but I wanted to document it anyway as adding your own recipe for pipeline precompiling is no longer necessary in Capistrano 2.8 as it was in the 3.1rc days.