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
更多推荐
导轨生产中的背景图像不起作用
发布评论