Search code examples
ruby-on-railsasset-pipelineproduction-environment

Missing assets on production mode - passenger on nginx


When i move to production many assets are missing. There is no background image but there are styles for background from css. Many JS doesn't load ..

I put in config production.rb :

  config.cache_classes = true


  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  config.assets.compress = true

  config.assets.compile = false

  config.assets.digest = true

In application.rb :

 config.assets.precompile += %w( ie.css )
    config.assets.paths << "#{Rails.root}/app/assets/fonts"

but fonts doesnt load. I see in public/assets all fonts but there isnt any on my site.

Can someone write answer - how config application to work on production ? Why i have xxx.jpg from css file but havent got yyy.jpg from that same css file..

CSS for background:

body{
line-height: 1;
background: #fff url('wallpaper.jpg') top left;

IMAGES location - assets/images

FONTS location - assets/fonts

Sometimes in chrome console i see :

GET ..../assets/wallpaper.jpg 404 (Not Found) xxxxxx/:11
GET...../assets/main_page.png 404 (Not Found) xxxxxx/:30
GET ...../assets/fonts/Lato-Bol.ttf 404 (Not Found) 

and sometimes not, but always there is no fonts and many assets.

My application css:

*= require_self
*= require chosen
*= require fancybox
*= require page
*= require_tree .
*/

Solution

  • Try using image-url instead of url.

    background: #fff image-url('wallpaper.jpg') top left;
    

    From the Asset Pipeline documentation:

    When using the asset pipeline, paths to assets must be re-written and sass-rails provides -url and -path helpers (hyphenated in Sass, underscored in Ruby) for the following asset classes: image, font, video, audio, JavaScript and stylesheet.