문제

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

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 also doesn't work.

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
도움이 되었습니까?

해결책

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

Further reading: http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top