轨道4,5资产管道:从资产缺少JS指纹asset_path [英] Rails 4 Asset Pipeline: Asset missing fingerprint in asset_path from js

查看:143
本文介绍了轨道4,5资产管道:从资产缺少JS指纹asset_path的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我部署一个Rails 4.0应用程序,其中包括HTML模板部分作为我们的前端JavaScript框架资产。虽然这些模板是资产管道的一部分,并得到妥善precompiled,当我在我们的JS文件调用 asset_path 从嵌入的宝石,它返回的路径,我们的模板< STRONG>无指纹。

I am deploying a Rails 4.0 application which includes HTML partial templates as assets for our front-end javascript framework. Although these templates are part of the asset pipeline and are properly precompiled, when I call asset_path from embedded ruby in our js files, it returns the path to our templates without the fingerprint.

我敢肯定,这是一个纯粹的资产管线的问题,但给你我们的技术栈的完整意义上的:我们使用Rails的4.0和Ruby 2.1,AngularJS为我们的前端MVC框架,的 AssetSync 可Rails和我们的CDN之间我们的资产同步。

I am quite certain that this is purely a Asset Pipeline question, but to give you a complete sense of our tech stack: We use Rails 4.0, Ruby 2.1, AngularJS for our front-end MVC framework, and AssetSync to synchronize our assets between Rails and our CDN.

包含在应用程序/资产/ application.js.erb (其中发生这种情况的一个例子文件:

An example of where this occurs (in a file included in app/assets/application.js.erb:

$routeProvider
    .when('/', {
      templateUrl: "<%= asset_path 'home.html' %>",
      controller: "HomeController"
    });

这尽早的伟大工程在当地,但作为 config.assets.digest = TRUE 在生产上,调用 asset_path 不正常因素的指纹。该模板是一个新的子目录模板中的应用程序/资产目录。所以在上面的例子中,home.html的资产是应用程序/资产/模板/ home.html做为。我们的JavaScript将自己一直在这一点上pcompiled $ P $,所以我想这可能是其中责令资产是pcompiled $ P $的问题。

This works great locally, but as soon as config.assets.digest = true in production, the call to asset_path does not properly factor in the fingerprint. The templates are in the app/assets directory within a new subdirectory templates. So in the above example, the home.html asset is at app/assets/templates/home.html. Our javascript has itself been precompiled at that point, so I'm thinking that it might be an issue of which order the assets are precompiled in.

我注意到在铁轨上Github上的几个问题( 1 ,<一个HREF =htt​​ps://github.com/rails/rails/issues/10866相对=nofollow> 2 ,的 3 )和一对夫妇因未正确设置指纹SO职位(<一href=\"http://stackoverflow.com/questions/17763123/rails-asset-pipeline-wrong-fingerprint?rq=1\">1, <一href=\"http://stackoverflow.com/questions/19598992/rails-4-asset-pipeline-doesnt-overwrite-assets-with-asset-path-references-to-ot?rq=1\">2),但找不到他们什么不被包含在所有...

I've noticed a few issues on the Rails Github (1, 2, 3) and a couple of SO posts about fingerprints not being set properly (1, 2), but can't find anything about them not being included at all...

任何帮助或想法,你可以提供将大大AP preciated。

Any help or ideas that you can provide would be much appreciated.

修改4/15 :忘了包括在我的应用程序扩展JavaScript文件中包含了 .erb 应用程序/资产/ application.js.erb )。感谢亚历克斯为没收。我上面更新它。
此外,按照 rel=\"nofollow\">,我证实,运行提出helper.asset_path(/home.html的)在生产打印该资产运行正确按手印URL Rails的控制台中。

Edit 4/15: forgot to include that the extensions on my application javascript file DOES include .erb (app/assets/application.js.erb). Thanks Alex for catching that. I've updated it above. Also, following instructions in this article on Heroku, I confirmed that running puts helper.asset_path("home.html") from within a Rails console running in production prints a properly fingerprinted URL for that asset.

推荐答案

这似乎与一个问题 AssetSync 宝石。我删除它,重新配置应用程序,以便Rails的服务资产,以及指纹识别正常工作。

This appears to be an issue with the AssetSync gem. I removed it, reconfigured the app so that Rails serves the assets, and the fingerprinting works fine.

如果任何人发现这个问题,并正在运行到同一个问题,我会建议不要使用AssetSync。据 Heroku的

If anyone else finds this question and is running into the same issue, I would recommend against using AssetSync. According to Heroku:

Many developers make use of Amazon’s S3 service for serving static assets that 
have been uploaded previously, either manually or by some form of build process.
Whilst this works, this is not recommended as S3 was designed as a file storage 
service and not for optimal delivery of files under load. Therefore, serving 
static assets from S3 is not recommended.

亚马逊CloudFront的是通过CDN服务资产preferred方法,并且是非常容易与一个Rails应用程序,供应自身的静态资产配置,实现相同的目标AssetSync。

Amazon CloudFront is the preferred method of serving assets through a CDN, and is very easy to configure with a Rails app that serves its own static assets, accomplishing the same goals as AssetSync.

这篇关于轨道4,5资产管道:从资产缺少JS指纹asset_path的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆