导轨生产中的背景图像不起作用 [英] Background images in rails production don't work

查看:138
本文介绍了导轨生产中的背景图像不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Background images in rails 4(production env) don't work. It seems to me that there is a problem with asset pipeline. When I write in css:

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

它生成 http://myapp.com/assets/image.jpg 它不起作用。如果我手动将URL更改为
image.jpg-fingerprint(来自公共/资产),那么一切都还可以。

it generates http://myapp.com/assets/image.jpg and it doesn't work. If I change url manually to image.jpg-fingerprint(from public/assets) then everything is okay.

ckeditor也不起作用。

ckeditor also doesn't work.

这是我的production.rb

Here is my 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


推荐答案

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

You are not using the asset pipeline - you are not using the fingerprinted, cached version of the files. To use the asset pipeline, you need to use the new helpers that point to the fingerprinted, cached version of the files. To do this, either embed erb in your css, or use sass. I'll use sass in my example:

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

Incorrect (doesn't use the asset pipeline):

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

更正(使用资产管道):

Correct (uses the asset pipeline):

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

进一步阅读: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

这篇关于导轨生产中的背景图像不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆