Rails部署不显示生产中的图像

use*_*201 4 ruby ruby-on-rails nginx amazon-web-services asset-pipeline

我正在使用AWS Opswork来部署我的rails应用程序

我正在使用独角兽+ Nginx,我被困在这个错误2天,我的应用程序工作正常,我得到我的CSS和javascript工作后做rake资产:预编译但我无法看到任何图像或fa图标在我的应用

我的所有图像都存储在app/assets/images中

在html视图中,我正在使用它 <img src="/assets/image.jpg">

我的图像在开发中完美加载,但在生产中没有

mwa*_*ngi 7

我有这个问题.我不得不重新编译我的资产.

  1. 通过runnning删除以前预编译的资产 rake assets:clobber
  2. 预编译 rake assets:precompile
  3. 重启应用程序/服务器

希望这可以帮助


Dus*_*sht 5

确保您的production.rb设置包括:

# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false

# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false

# Generate digests for assets URLs
config.assets.digest = true
Run Code Online (Sandbox Code Playgroud)

这是使用 SCSS 预编译资产的方法:

#application.css.scss (yes, you need to rename it)
@import 'layout/body'


#app/assets/stylesheets/layout/body.css.scss
body {
    background: asset_url('image.jpg')
}
Run Code Online (Sandbox Code Playgroud)

执行上述操作时,请确保像这样进行预编译:

RAILS_ENV=production rake assets:precompile
Run Code Online (Sandbox Code Playgroud)