1

I deployed my project to production and some of my assets don't work. Those assets, which I use in html.erb with

<%= image_tag('outstaffing/outstaff2.svg') %>

work normally and return

<img src="/assets/outstaffing/outstaff2-eade8e303c63a428e7430e84866b732dae91cda0639d8d3d422c2ee86fb254aa.svg" alt="Outstaff2 eade8e303c63a428e7430e84866b732dae91cda0639d8d3d422c2ee86fb254aa">

However fonts and some images don't. I have app/assets/fonts/RobotoCondensedRegular.ttf and app/assets/images/common/footer.svg which I try to call from css files.

style.css.scss

@font-face {
   font-family: 'RobotoRegular';
   src: url(font-path('RobotoCondensedRegular.ttf'))  format('truetype');
}

#some_div{
   background: asset-url('common/footer.svg');
}

After precompilling I have public/assets/styles-h5digest.css with

@font-face{
  font-family:'RobotoRegular';
  src:url("/assets/RobotoCondensedRegular-4a7c36df4318fee50a8159c3a0ebde4572abab65447ae4a651c2fe87212302b5.ttf") format("truetype")
}

This should work but returns me errors:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

Server is trying to load assets/fonts/RobotoCondensedRegular.ttf but file name should be with digest. The same thing is with footer image.

I have already tried to change assets.rb, production.rb and application.rb in many ways. Moreover, I tried different extensions of my css files (css, css.scss, scss, css.erb) and helpers (asset-url, image-url, asset-data-url, asset_data_path, <%= asset_path() %>).

I am using Rails 4.2.0 and ruby 2.2.3.

My production.rb

config.serve_static_files = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = false
config.assets.digest = true

My application.rb

config.assets.enabled = true
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.paths << Rails.root.join('app', 'assets', 'images', 'img', 'main')

My assets.rb

Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf|jpg|png)\z/
Rails.application.config.assets.precompile += ['styles.css', 'careers.css', 'team.css', 'home.css', 'services.css', 'contacts.css']

Error from log:

"GET /assets/fonts/RobotoCondensedBold.ttf HTTP/1.1" 500 1812 "http://...ip..../assets/application-6b568a81a81290ff96d145fa1f76bbf33919b85dad0f4235d8bf8759787a5076.css"

I think problem is in my server (apache) but i have no solution.

4
  • Can you run RAILS_ENV=production bundle exec rake assets:precompile locally? Commented Apr 13, 2016 at 15:57
  • run this at localhost, run server in production mode and all is good. pushed to apache and got the same error Commented Apr 13, 2016 at 16:30
  • And you're not caching anything in your browser? Only fonts and images don't have a digest? Commented Apr 13, 2016 at 16:42
  • only images and fonts from css files don't have digest) they do have in folders, but not in call Commented Apr 13, 2016 at 18:23

1 Answer 1

1

I added these two gems to my Gemfile:

gem 'rails_serve_static_assets'
gem 'rails_stdout_logging'

And set in my production.rb

config.serve_static_files = false

Now all fonts and images are working good.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.