Rails [求助] rails 项目背景图片:background:url () 在阿里云服务器上不能显示出来?

Sylor-huang · January 26, 2019 · Last by huacnlee replied at January 28, 2019 · 1143 hits

图片在app/assets/images 文件夹下。

css 文件在app/assets/stylesheets文件夹下。

背景图片 css 如下

.loginBox{
  background: url("../assets/login_bg.png") no-repeat center;

  background-size: cover;
}

我把项目部署在阿里云上后,在 chrome 的审查元素下发现调用的路径为 css,图片不能正确显示:

Host: www.xxxx.com
Referer: https://www.xxxx.com/assets/application-846c3d1ba38908834ae2d2f7e5806fee3121c960b3ca98014b133c815c42dba4.css

但是当我在本地的时候,同样的路径,是可以正确显示的,但审查元素时,调用路径有点区别:

Host: 127.0.0.1:3000
If-None-Match: "5f0033f9ebd5af371ec277291421e1b28036dc04b284f4d87b0d839ca60a89a0"
Referer: http://127.0.0.1:3000/assets/application.self-e000278a056ed6286cefac71cf6ac663d225c1c4eb315c88e2f37fc00426aee5.css?body=1

请问大家,我该怎么修改才可以在阿里云上正确显示?非常感谢。

background: image-url("login_bg.png") no-repeat center;

1 楼正解,有个东西叫 asset pipline 你查一下就知道了

Reply to libuchao

@libuchao 正解,非常感谢~~

建议阅读 Rails Guides - Asset Pileline,理解这个机制

https://guides.rubyonrails.org/asset_pipeline.html

You need to Sign in before reply, if you don't have an account, please Sign up first.