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.
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.