1

導軌4(製作環境)中的背景圖像不起作用。在我看來,資產管道存在問題。當我用css寫入時:導軌制作中的背景圖像不起作用

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

它生成http://myapp.com/assets/image.jpg並且它不起作用。如果我手動更改網址爲 image.jpg指紋(來自公共/資產),那麼一切都可以。

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 

回答

3

您沒有使用資產管道 - 不使用的文件的採集指紋,緩存版本。要使用資產管道,您需要使用指向文件的指紋緩存版本的新幫助程序。要做到這一點,要麼將erb嵌入到css中,要麼使用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,我會在我的例子中使用SASS