Rails 4 - 生产图像和字体未指向指纹

Rails 4 - production images and fonts not pointing to fingerprint

我将自定义主题导入我的 Rails 应用程序主页。我已将整个文件夹复制到 app/assets/customlibrary 中,这样我就不必拆分主题文件了。

当我在生产环境中 运行 我的应用程序时,Rails 无法在 app/assets/customlibrary/* 中找到指纹资产 app/assets/customlibrary/css/style.css.

例如 style.cssbackground: url("../images/hero-image.jpg") 结果是 GET http://localhost:3000/assets/images/hero-image.jpg 404 (Not Found)

我不知道如何解决这个问题。有什么建议吗?

文件夹结构

app/assets/customlibary/css/*
app/assets/customlibary/css/style.css
app/assets/customlibary/js/*
app/assets/customlibary/fonts/*.(svg|eot|woff|tff|)
app/assets/customlibary/images/*
app/assets/customlibary/images/hero-image.jpg

app/assets/stylesheets/themes/theme.css'
app/assets/stylesheets/style1.css'
app/assets/stylesheets/style2.css'

application.rb

config.active_support.escape_html_entities_in_json = true
config.filter_parameters += [:password]
config.encoding = "utf-8"

# setup bower components folder for lookup
config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components')
config.assets.paths << Rails.root.join('vendor', 'assets', 'bower_components', 'bootstrap-sass-official', 'assets', 'fonts')
config.assets.paths << Rails.root.join('app', 'assets', 'customlibrary')

# customlibrary assets
config.assets.precompile += %w( css/* fonts/* images/* js/* )
# normal stuff
config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/
config.assets.precompile << /\.(?:png|jpg)$/
config.assets.precompile += %w( base.css )
config.assets.precompile += ['themes/theme.css']
config.assets.precompile += ['style1.css', style2.css', ... ]

production.rb

config.cache_classes = true

config.eager_load = true

config.consider_all_requests_local       = false
config.action_controller.perform_caching = true

config.serve_static_assets = true

config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass

config.assets.compile = false

config.assets.digest = true

config.assets.version = '1.0'

config.log_level = :debug

config.assets.paths 中添加路径并不意味着它可以从应用程序的 Web 根目录中获取资产。 (即my_app/public

它将一个目录添加到 Sprockets 和资产助手使用的查找路径中。从样式表链接到资产时,您可以将扩展名更改为 .css.erb 并使用插值:

.class { background-image: url(<%= image_path 'image.png' %>) }

如果您正在使用 SASS,sass-rails 将 Rails 资产助手映射到 SASS 函数,因此您可以只使用:

.class { background-image: image-url("image.png") }

这不需要您重命名文件。