Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.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
RoR-运行应用程序的生产无法从CSS加载图像_Css_Ruby On Rails_Ruby - Fatal编程技术网

RoR-运行应用程序的生产无法从CSS加载图像

RoR-运行应用程序的生产无法从CSS加载图像,css,ruby-on-rails,ruby,Css,Ruby On Rails,Ruby,我有一个rails应用程序,它在开发过程中运行良好,但无法获得从css文件加载的特定图像。但是html.erb上的图像加载良好 以下是我的css中的字符串: .greyscale .banner-logo { background: url(/assets/theme/greyscale/greyscale_main_logo.png) no-repeat center center; } 这是my production.rb(删除注释): 这是my development.rb(删除

我有一个rails应用程序,它在开发过程中运行良好,但无法获得从css文件加载的特定图像。但是html.erb上的图像加载良好

以下是我的css中的字符串:

.greyscale .banner-logo {
    background: url(/assets/theme/greyscale/greyscale_main_logo.png) no-repeat center center;
}
这是my production.rb(删除注释):

这是my development.rb(删除注释):

这是我的资产。rb:

Rails.application.config.assets.version = '1.0'
Rails.application.config.assets.precompile += [/.*\.js/,/.*\.css/]

我需要在我的production.rb中添加/修改哪些内容才能查看css文件中的图像?

在css中尝试类似的内容

url(image-path('greyscale_main_logo.png'))

图像路径通常用于获取资产文件夹的正确路径。您可能已经将上面的演示扩展到“主题/灰度/灰度主标志…”

这是因为资产管道在资产文件名中使用摘要来引用生产中的资产。要修复此问题,请使用
资产路径
,或
图像路径

.greyscale .banner-logo {
    background: url(image-path('theme/greyscale/greyscale_main_logo.png')) no-repeat center center;
}

这将适用于引用
app/assets/images/greyscale/greyscale\u main\u logo.png

我遇到了类似的问题,以这种方式指向图像会有所帮助

.greyscale .banner-logo {
    background-image: image-url("theme/greyscale/greyscale_main_logo.png") no-repeat center center;
}

这样,资产管道将尝试在
assets/images/theme/grescale
文件夹中查找图像。

根据原始文件扩展名,将文件扩展名更改为
css.erb
scss.erb
。然后你可以用

background: url("<%= asset_path 'theme/greyscale/greyscale_main_logo.png') %>" no-repeat center center;
background:url(“”无重复中心;

预编译过程中出现错误吗?浏览器控制台出现了什么问题?
.greyscale .banner-logo {
    background-image: image-url("theme/greyscale/greyscale_main_logo.png") no-repeat center center;
}
background: url("<%= asset_path 'theme/greyscale/greyscale_main_logo.png') %>" no-repeat center center;