资产生成的文件:预编译与最小 rails 4 站点中由 stylesheet_link_tag(缺少摘要)生成的 url 不匹配 [英] files produced by asset:precompile don't match urls generated by stylesheet_link_tag (missing digest) in minimal rails 4 site

查看:22
本文介绍了资产生成的文件:预编译与最小 rails 4 站点中由 stylesheet_link_tag(缺少摘要)生成的 url 不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Ruby 2.0.0-p247Rails 4.0.0

如果我像这样制作一个最小的 Rails 4 站点:

If I make a minimal Rails 4 site like this:

rails new minimal
cd minimal
rails generate controller home index
tee config/routes.rb <<EOF
Minimal::Application.routes.draw do
  root 'home#index'
end
EOF

然后用

rake assets:precompile

它生成如下资产:

I, [2013-09-04T17:05:36.992951 #3549]  INFO -- : Writing /WORKINGDIR/minimal/public/assets/application-723d1be6cc741a3aabb1cec24276d681.js
I, [2013-09-04T17:05:37.052303 #3549]  INFO -- : Writing /WORKINGDIR/minimal/public/assets/application-f1a14051f17824976271b9c0460232f0.css

但是如果我在生产模式下启动服务器,

But if I start the server in production mode, with

RAILS_ENV=production rails s

HTML 中生成的 URL 不指向预编译文件:

The generated URLs in the HTML don't point at the precompiled files:

<link data-turbolinks-track="true" href="/stylesheets/application.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/javascripts/application.js"></script>

我更希望:

<link data-turbolinks-track="true" href="assets/application-f1a14051f17824976271b9c0460232f0.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/application-723d1be6cc741a3aabb1cec24276d681.js"></script>

默认的 config/environments/production.rb 设置说使用摘要:

The default config/environments/production.rb settings say to use digests:

config.assets.digest = true

但是好像被选择性忽略了?

But it seems to be selectively ignored?

我错过了什么吗?

更新:

我刚刚在 Rails 4.2.3 中对此进行了测试,这似乎已修复,但是我们需要将更多环境变量传递给 rails s 命令以在生产模式下启动:

I just tested this in Rails 4.2.3 and this appears to be fixed, however we need to hand a few more environment variables into the rails s command to start in production mode:

SECRET_KEY_BASE=$(rake secret) RAILS_SERVE_STATIC_FILES=true RAILS_ENV=production rails s

推荐答案

在我写这个问题的时候,我看到了这篇博客文章,它表明这是一个错误.

While I was writing up this question I came across this blog post which suggests it is a bug.

http://railsblog.kieser.net/2013/08/rails4-phusion-passenger-asset-pipeline.html

在各种建议中,只需将编译回退设置为 true...

Of the various suggestions, just setting the compilation fallback true...

config.assets.compile = true

似乎足以让 Rails 生成适当消化的 URL:

seems to be sufficient to kick Rails in to generating appropriately digested URLs:

<link data-turbolinks-track="true" href="/assets/application-f1a14051f17824976271b9c0460232f0.css" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/application-723d1be6cc741a3aabb1cec24276d681.js"></script>

另一个建议,明确设置 RAILS_ENV 和 RAILS_GROUPS 似乎在预编译文件上生成不同的摘要字符串,但无论如何它们似乎总是与生成的 HTML 匹配.

The other suggestion, explicitly setting RAILS_ENV and RAILS_GROUPS seemed to produce different digest strings on the precompiled files, but they always seem to match up with the generated HTML regardless.

这篇关于资产生成的文件:预编译与最小 rails 4 站点中由 stylesheet_link_tag(缺少摘要)生成的 url 不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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