【问题标题】:Background images in rails production don't work轨道生产中的背景图像不起作用
【发布时间】:2013-10-15 18:13:18
【问题描述】:

rails 4(生产环境)中的背景图像不起作用。在我看来,资产管道存在问题。当我用 css 编写时:

selector{
  background-image: url(image.jpg)
} 

它会生成http://myapp.com/assets/image.jpg,但它不起作用。如果我手动将 url 更改为 image.jpg-fingerprint(from public/assets) 那么一切都好。

ckeditor 也不起作用。

这是我的制作.rb

  config.cache_classes = true
  config.assets.enabled = true
  config.eager_load = true
  config.assets.precompile += Ckeditor.assets
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.assets.js_compressor = :uglifier
  config.assets.compile = false
  config.assets.digest = true
  config.assets.version = '1.0'
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
  config.log_level = :info
  config.log_formatter = ::Logger::Formatter.new

【问题讨论】:

    标签: javascript ruby-on-rails image asset-pipeline production-environment


    【解决方案1】:

    您没有使用资产管道 - 您没有使用文件的指纹缓存版本。要使用资产管道,您需要使用指向文件的指纹缓存版本的新帮助程序。要做到这一点,要么将 erb 嵌入到你的 css 中,要么使用 sass。我将在示例中使用 sass:

    不正确(不使用资产管道):

    .class
      background-image: url('image.jpg')
    

    正确(使用资产管道):

    .class
      background-image: image-url('image.jpg')
    

    延伸阅读:http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

    【讨论】:

      猜你喜欢
      • 2019-05-01
      • 2021-09-08
      • 2016-08-24
      • 2016-05-04
      • 2023-03-03
      • 2018-05-08
      • 2016-09-27
      • 1970-01-01
      相关资源
      最近更新 更多