Rails 4.1 - ActionController :: RoutingError (No route mappings [GET] "/fonts/....ttf") - @ font problems

It seems to me that I tried all the solutions that I found here and on some blogs, but something is still wrong, and I have no idea what.

My mistake:

... Started GET "/fonts/amaze.ttf" for 83.9.18.180 at 2014-11-26 09:10:21 +0000 ... app[web.1]: ActionController::RoutingError (No route matches [GET] "/fonts/amaze.ttf"): ... 

Of course, it doesn’t work on localhost either.

I use rails 4.1.1

My font is in:

 assets/fonts/amaze.ttf 

I even moved it to check if this would work: assets / amaze.ttf -it was not.

My current solution in application.css.scss is:

 @font-face { font-family: 'Amaze'; src: font-url('amaze.ttf'); } .amaze { font-family: 'Amaze'; } 

I tried some configuration in application.rb but had no effect:

 config.assets.enabled = true config.assets.paths << "#{Rails.root}/app/assets/fonts" config.serve_static_assets = true config.assets.js_compressor = :uglifier config.assets.compile = true config.assets.digest = true config.assets.version = '1.0' config.assets.paths << Rails.root.join('app', 'assets', 'fonts') config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/ 

Do I even need to configure anything in application or development / production files?


EDIT

(view) FIXED a PROBLEM

The problem was that I had a broken font ...

more info: I had a font from here http://fontzone.net/download/amaze-normal and it was broken (I mean not completely broken, it worked on linux, but not with the font, I don’t know why, if it worth the effort, try to figure out what the problem is)

I tried another font from a different source: http://www.fontcubes.com/Amaze.font

and it worked! yeah! -


EDIT

I had a similar problem with a lot of fonts (both otf and ttf), so I would say that the problem is still open; p

+7
ruby-on-rails fonts font-face
source share
5 answers

Use the asset pipeline or move fonts to the public directory.

Your problem is that the /fonts/amaze.ttf path /fonts/amaze.ttf not get into the Rails Asset Pipeline. To use the Project Console, for example, /assets/fonts/amaze.ttf or /assets/amaze.ttf , you need to provide /assets .

Here you have two main options:

  • Update path request:

    So use /assets/amaze.ttf instead of /fonts/amaze.ttf .

    Remember that for the /assets/fonts/amaze.ttf path /assets/fonts/amaze.ttf work, you need to put the amaze.ttf font in /app/assets/fonts/fonts/ or /vendor/assets/fonts/fonts/ . The dual fonts directory provides the fonts the /public/assets directory after compiling the assets. See this answer for more information.

  • Move the fonts directory to the public directory:

    Since the requested path still does not use the Pipeline Asset Pipeline, you can simply move the fonts directory to the /public/ directory and the web server will automatically serve it. Therefore, your fonts should be located in /public/fonts/amaze.ttf etc.

That should do it!

+15
source share

I also run into this problem with the font - awesome, but these are my general studies for fonts.

I am creating a new directory called app / assets called fonts. Then copy all the fonts and add them to the assets in the application.rb file, for example:

 config.assets.paths << Rails.root.join("app", "assets", "fonts") 

rename your font-awesome.css to font-awesome.css.scss.erb and change the @ font-face declaration in it like this

  @font-face { font-family: "FontAwesome"; src: url('<%= asset_path('fontawesome-webfont.eot')%>'); src: url('<%= asset_path('fontawesome-webfont.eot?#iefix')%>') format('eot'), url('<%= asset_path('fontawesome-webfont.woff')%>') format('woff'), url('<%= asset_path('fontawesome-webfont.ttf')%>') format('truetype'), url('<%= asset_path('fontawesome-webfont.svg#FontAwesome')%>') format('svg'); font-weight: normal; font-style: normal; } 

Hope this will be helpful :) There are more Font-face links

+1
source share

For me it was a file permission error, I copied the files from another computer. once i fixed the permissions it worked.

0
source share

For me, it was as simple as my import in application.scss using https// instead of https:// for the URL. Must read carefully next time.

0
source share

Thank you, guys.

I found a solution, why not put fonts/*.ttf in app/assets/images/fonts/*.ttf for dev env?

At the same time, leave config/environments/development.rb the same as the default config.serve_static_assets = false false.

This works for me.

0
source share

All Articles