RoR-运行应用程序的生产无法从CSS加载图像
我有一个rails应用程序,它在开发过程中运行良好,但无法获得从css文件加载的特定图像。但是html.erb上的图像加载良好 以下是我的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(删除
.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;