In my routes, I define a global category with some ID to load dynamic content:
get "/:global_category/:id" => "pages#index"
The route is placed on the bottom of routes.rb. All easy and no problem, at least on development. Now I also load some webfonts via CSS into my app and when I' on production, I get the following exception whenever my fonts are loaded:
undefined method `id' for nil:NilClass
The affected URL is: http://www.example.com/assets/Sansation_Bold-webfont.woff
I load fonts that are located in /assets/fonts in a sass file like this:
@font-face
font-family: 'ApolloASM'
src: url('ApolloASM-webfont.eot')
src: url('ApolloASM-webfont.eot?#iefix') format('embedded-opentype'), url('ApolloASM-webfont.woff2') format('woff2'),url('ApolloASM-webfont.woff') format('woff'),url('ApolloASM-webfont.ttf') format('truetype'),url('ApolloASM-webfont.svg#apollo_asmregular') format('svg')
font-weight: normal
font-style: normal
There is obviously a conflict with my routes and the assets pipeline. Only on production (I deploy on heroku) I can reproduce this so I tried to modify my production.rb but after looking into the docu (http://guides.rubyonrails.org/asset_pipeline.html) I still don't really know what to do.
I also tried to precompile assets.
That does not seem to be the cause of the issue and also my Fonts are all loaded correctly! Any hints are appreciated.
I solved it by using the sass helper "font-url":
no need to pre-compile or add anything in the production.rb or application.rb file
make sure that fonts are all stored in the /app/assets/fonts directory.