【发布时间】:2012-04-07 05:14:27
【问题描述】:
我正在尝试在生产环境中预编译资产。但预编译后,应用程序找不到图像文件、javascripts 文件、css 文件...等。
我运行这个命令:
RAILS_ENV=production rake assets:precompile
我得到了这个结果:
/home/hyperrjas/.rvm/rubies/ruby-1.9.2-p318/bin/ruby /home/hyperrjas/.rvm/gems/ruby-1.9.2-p318/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
/home/hyperrjas/.rvm/rubies/ruby-1.9.2-p318/bin/ruby /home/hyperrjas/.rvm/gems/ruby-1.9.2-p318/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
然后我尝试重新加载页面,我看到了这个:
我正在使用 nginx + 独角兽。
为什么应用找不到资产、图片、css、javascript...
已编辑**
我从 application.html.erb 加载我的资产布局:
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
我的 nginx.conf 中有这个在服务器 { }
location ~ ^/(assets)/ {
root ~/mydomain.com/current/public;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
谢谢
【问题讨论】:
-
你在environments/production.rb中设置了“config.assets.digest = true”吗?
-
是的,我在
config/environments/production.rb下一个:# Generate digests for assets URLs config.assets.digest = true -
您能否从 html 源代码或服务器日志中看到正在请求的生成 404 的路径是什么?
-
我可以在 html 标签中的 firebug 中看到:
<link type="text/css" rel="stylesheet" media="screen" href="/assets/application-757164eb38463ea8d323f05b3a3238ca.css"> <script type="text/javascript" src="/assets/application-203db49c9ee856182159ad4bce51bf0e.js"> -
如何在视图中包含资产?您是直接引用资产还是引用清单?
标签: ruby-on-rails ruby-on-rails-3 asset-pipeline production-environment