Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 赫罗库没有';不加载预编译的资产_Ruby On Rails_Heroku_Assets - Fatal编程技术网

Ruby on rails 赫罗库没有';不加载预编译的资产

Ruby on rails 赫罗库没有';不加载预编译的资产,ruby-on-rails,heroku,assets,Ruby On Rails,Heroku,Assets,我在Heroku上有一个暂存服务器,它的代码与我的生产服务器(也在Heroku上)的代码相同,并且没有任何资产在暂存中加载,但它们都在prod.Rails 3.2.11中工作 assets:precompile可以工作,我可以使用bash登录并查看在public/assets下预编译的所有资产。但是当我试图查看它们时,我总是得到404 日志中有很多这样的内容: ActionController::RoutingError (No route matches [GET] "/assets/team

我在Heroku上有一个暂存服务器,它的代码与我的生产服务器(也在Heroku上)的代码相同,并且没有任何资产在暂存中加载,但它们都在prod.Rails 3.2.11中工作

assets:precompile可以工作,我可以使用bash登录并查看在public/assets下预编译的所有资产。但是当我试图查看它们时,我总是得到404

日志中有很多这样的内容:

ActionController::RoutingError (No route matches [GET] "/assets/team_accessories_ad.png"):
我觉得我什么都试过了。即使文件在那里,也不会通过路由到公共/资产来获取它们。我是不是做错了什么

谢谢

编辑:在我的例子中,它是由12factor gem()引起的。当我移除这颗宝石时,一切都开始工作了


谢谢

您的问题是您的图像在资产文件中没有动态链接:


SCSS

Rails与捆绑在一起,因为这允许您正确预编译映像资产。当您使用
rake assets:precompile
时,SCS是动态呈现的,而CSS不能动态呈现这些资产

因为当它们被预编译时,这意味着许多图像资产(预编译前的名称为
XXXX.png
)在预编译后会有断开的路径(使它们
XXX-dsdasdfew5823459432jt342j52435.png

解决方案是在SCS中使用动态映像路径:

#app/assets/stylesheets/images.css.scss
body {
    background: asset_url('image_path.png')
}

这允许您在预编译时动态渲染图像路径,从而使您能够在生产中查看图像

我也遇到了同样的问题,结果证明这是由上的更改引起的。我将rails_12factor gem添加到我的生产组,它解决了这个问题。我想我可以通过添加
rails\u serve\u static\u资产来逃脱,但我没有这样做。

你链接到的图像不正确-你需要使用rails的资产助手。你怎么会这样想?因为图像文件名末尾没有一个大数字?我也在日志heroku[router]:at=info method=get path=/assets/logo-8a3a8daaac49c2c2e20f4c6ef188623a9.png host=.herokuapp.com fwd=”“dyno=web.1 connect=1ms service=141ms status=404 bytes=1330
是。如果您能提供一个您试图如何访问这些资产的示例,我们可能会提供实际帮助。通过
http://.herokuapp.com/assets/logo.png
,从应用程序通过
=image_标记“btnBack.png”
或纯
%img{:src=>'/assets/invite.png'}
。感谢image_标记示例将起作用,因为它使用一个Rails助手自动添加摘要,而其他两个不会。