【发布时间】:2012-03-15 07:10:13
【问题描述】:
我的问题与Rails 3.2 Asset Pipeline with Passenger Endless Errors 类似,只是当我尝试真正去
<link href="/assets/application-eed7996ee9017637f923133371ab3e92.css" media="all" rel="stylesheet" type="text/css" />
我得到一个 404。这是我不明白的事情。它在 /assets/ 中查找,但是当我查看部署的代码时,资产仅在 /public/assets 中,这实际上是 /var/www/myapp/shared/assets 的符号链接。那么到底是什么负责告诉应用在 /assets 中查找会产生正确的结果呢??
我正在使用 Rails 3.2.0、ruby-1.9.3-p125,部署到 Ubuntu、Apache 和 Thin。
我应该澄清一下:我的资产确实已部署到服务器上。在需要提供服务之前,一切都运行良好,在这种情况下,production.log 告诉我它正在 /assets/application-eed7996ee9017637f923133371ab3e92.css 中寻找它们,它是 404。
对于每个请求,我的 thin.log 都会说
cache: [GET /] miss
和 production.log 说
ActionController::RoutingError (No route matches [GET] "/assets/application-abecf2e096af9ee80697fd49e79a55e7.js"):
更新
@Brandan 感谢您的帮助。我的资产确实在RAILS_ROOT/public/assets。我把它放在我的 Apache vhost 文件中:
DocumentRoot /var/rails/myappname/current/public
RewriteEngine On
XSendFile On
XSendFilePath /var/rails/myappname #not even sure if this line is needed
<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
我的 RAILS_ROOT/config/environments/production.rb 设置:
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
【问题讨论】:
-
如何创建链接?
-
在我的布局中我说
<%= stylesheet_link_tag "application", :media => "all" %>和<%= javascript_include_tag "application" %> -
您是否预编译了资产?
-
是的,我有最新的 capistrano 并且正在我的 Capfile 中使用
load 'deploy/assets'来做到这一点。但即使我手动预编译资产,仍然不行。 -
也有这个问题。我很想知道原因。
标签: ruby-on-rails ruby-on-rails-3 apache asset-pipeline thin