Search code examples
ruby-on-railsfontscapistranoruby-on-rails-5

Rails 5 - vendor assets are not loaded on production (fonts only)


It's perfectly working in development, but not in production. It's not finding the following files:

/assets/fontello.woff
/assets/fontello.ttf

Here is the setup:

  1. fonts files:

enter image description here

  1. assets.rb

    Rails.application.config.assets.paths << Rails.root.join('app', 'vendor', 'assets', 'fonts')
    Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/
    
  2. fontello.css

    @font-face {
      font-family: 'fontello';
        src: url('/assets/fontello.eot');
        src: url('/assets/fontello.eot#iefix') format('embedded-opentype'),
        url('/assets/fontello.woff') format('woff'),
        url('/assets/fontello.ttf') format('truetype'),
        url('/assets/fontello.svg#fontello') format('svg');
      font-weight: normal;
      font-style: normal;
    }
    

As I said, everything is working fine in development. I have try a lot of things. For example:

  1. moving the fonts in the public folder (as my images there are loaded)
  2. add the following line in the assets.rb:

    Rails.application.config.assets.precompile += [/^[-_a-zA-Z0-9]*\..*/]
    

but nothing worked.

Could you advise anything else to try?


Solution

  • What does ls public/assets outputs in production?

    Probably your files are there with a digest (ex. fontello-XXXX.ttf). In this case you have to use the font helpers in your sass (not css) - ex. in your font-family block: src:font-url('fontello.ttf')