导轨生产中的背景图像不起作用

时间:2013-10-15 18:13:18

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

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

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

它生成http://myapp.com/assets/image.jpg并且它不起作用。如果我手动更改网址 image.jpg-fingerprint(来自公共/资产)然后一切都很好。

ckeditor也不起作用。

这是我的production.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

1 个答案:

答案 0 :(得分:3)

您没有使用资产管道 - 您没有使用文档的指纹缓存版本。要使用资产管道,您需要使用指向文档的指纹缓存版本的新助手。要做到这一点,要么将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