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

问题描述 投票:3回答:3

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

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

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

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

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

ruby-on-rails ruby amazon-web-services nginx asset-pipeline
3个回答
7
投票

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

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

希望这可以帮助


4
投票

确保您的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

这是您使用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')
}

执行上述操作时,请确保预编译如下:

RAILS_ENV=production rake assets:precompile

0
投票

只是用rails方式写图像标签而不是html方式:

image_tag("icon.png")
# => <img alt="Icon" src="/assets/icon.png" />
image_tag("icon.png", size: "16x10", alt: "Edit Entry")
# => <img src="/assets/icon.png" width="16" height="10" alt="Edit Entry" />

rake assets:precompile资产生成到应用程序的公共文件夹中,并从public / assets文件夹中获取(预编译的图像,css,js)。

© www.soinside.com 2019 - 2024. All rights reserved.