Search code examples
ruby-on-railsroutesrails-routingembedded-fonts

How to make Rails route to response for the font files (eot)?


In my rails(2.x) application. I want to use custom font in my view. So that I added the font files in public under fonts folder. When I try to get the fonts in url or via application, it through routing error. I guess rails routes not able to recognize the format/file. Correct me if I am wrong and give me solution

css code:

@font-face {
    font-family: 'Effra';
    src: url('/fonts/effra_std_rg-webfont.eot');
    src: url('/fonts/effra_std_rg-webfont.eot?#iefix') format('embedded-opentype'),
        url('/fonts/effra_std_rg-webfont.woff') format('woff'),
        url('/fonts/effra_std_rg-webfont.ttf') format('truetype'),
        url('/fonts/effra_std_rg-webfont.svg#EffraRegular') format('svg');
    font-weight: normal;
    font-style: normal;

}

Note: I can able to get woff, ttf file by directly typing the path but not eot file.

Error trace:
Unknown action
No action responded to fonts. Actions: XXXXXXsomeactionsXXXXX and rescue_404

Thanks in advance, Arun.


Solution

  • I fixed the above issue by moving the font folder under public/stylesheets/fonts. and made the above code as below.

     font-face {
        font-family: 'Effra';
        src: url('fonts/effra_std_rg-webfont.eot');
        src: url('fonts/effra_std_rg-webfont.eot?#iefix') format('embedded-opentype'),
            url('fonts/effra_std_rg-webfont.woff') format('woff'),
            url('fonts/effra_std_rg-webfont.ttf') format('truetype'),
            url('fonts/effra_std_rg-webfont.svg#EffraRegular') format('svg');
        font-weight: normal;
        font-style: normal;
    }
    

    Hope this will help to others.