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

编程入门 行业动态 更新时间:2024-10-24 18:26:28
本文介绍了导轨生产中的背景图像不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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) }

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

it generates myapp/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.assetspile = 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')

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

更多推荐

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

本文发布于:2023-05-31 10:04:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/389546.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:导轨   不起作用   图像   背景

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!