Rails为什么找不到我的资产? [英] Why won't Rails find my assets?

查看:76
本文介绍了Rails为什么找不到我的资产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在生产模式下,Rails似乎无法从资产管道中找到任何预编译的资产.

When in production mode, rails can't seem to find any precompiled assets from the asset pipeline.

我使用的是在CentOS上的RVM内运行的rails 3.2.0和ruby 1.9.3.没有其他Web服务器与此应用程序一起运行.该应用程序直到最近才更新为使用资产管道,因为它最初是Rails 3.0应用程序.

I'm using rails 3.2.0 and ruby 1.9.3 running inside RVM on CentOS. No additional web server is running in conjunction with this application. The application was only recently updated to use the asset pipeline, as it was originally a rails 3.0 app.

运行后

rake assets:clean
rake assets:precompile

正如我所期望的,我在公共/资产中看到了散列的内容.文件末尾的哈希值与我在页面源代码中看到的哈希值匹配.

I see the hashed content in public/assets, as I would expect. The hashes at the end of the files match those I see in the page source.

但是在运行时,这是我看到的Rails尝试提供的每项资产:

Yet at runtime, here's what I see for every asset Rails tries to serve:

Started GET "/assets/application-892c6227e631daf9a8e041b1d4d002ec.css" for 75.149.58.169 at 2012-03-14 11:42:43 -0700

ActionController::RoutingError (No route matches [GET] "/assets/application-892c6227e631daf9a8e041b1d4d002ec.css"):

我不是指每个资产所在的文件夹;所有对资产的引用如下所示:

I'm not referring to the folder that each asset is housed in; all references to assets look like these:

//css:
.class {
  background: url(asset.png) no-repeat;
}

//erb:
<%= image_tag "asset.png" %>
<%= link_to "page", :class => "class" %>

在production.rb中设置管道的相关设置:

Asset pipeline pertinent settings in production.rb:

config.serve_static_assets = false
config.assets.enabled = true
config.assets.compress = true
config.assets.debug = false
config.assets.compile = false
config.assets.digest = true

最后,从config/application.rb获取资产设置:

And lastly, asset settings from config/application.rb:

config.assets.enabled = true
config.assets.version = '1.0'

启动Rails服务器进程的用户已经具有对公共/资产的读取,写入和执行权限,因此我认为这不是权限问题.我错过了配置步骤吗?

The user starting the rails server process has read, write and execute permissions on public/assets, so I don't think it's a permissions issue. Have I missed a configuration step?

修改

我注意到没有错误指出资产未进行预编译,因此我尝试通过在主机路径末尾附加"/assets/application-892c6227e631daf9a8e041b1d4d002ec.css"来从网页访问样式表:

I noticed that there are no errors stating that assets are not precompiled, so I tried to access a stylesheet from the web page by appending"/assets/application-892c6227e631daf9a8e041b1d4d002ec.css" to the end of the host path:

http://www.myapp.com"/assets/application-892c6227e631daf9a8e041b1d4d002ec.css"

这有效,并且打开了样式表.

This worked and the stylesheet opened.

推荐答案

对此问题的进一步研究产生了这篇SO文章:

Further researching of this issue yielded this SO article:

application.css未用作资产

似乎

config.serve_static_assets = false

只要我的Rails应用程序不在Apache或nginx后面运行,这是不正确的设置

Is an incorrect setting as long as my Rails application is not running behind Apache or nginx

这篇关于Rails为什么找不到我的资产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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