2013-05-06 53 views
5

我想要的字体添加到我的Rails应用程序在此之后进行预编译是我做了什么:Heroku的Rails的资产管道失败添加字体

的字体到:

-app 
--assets 
---fonts 

SCSS:

@font-face { 
    font-family: LigatureSymbols; 

    src: font-url('LigatureSymbols211.eot'); 
    src: local('LigatureSymbols'), 
     font-url('LigatureSymbols211.eot?#iefix') format('embedded-opentype'), 
     font-url('LigatureSymbols211.woff') format('woff'), 
     font-url('LigatureSymbols211.ttf') format('truetype'), 
     font-url('LigatureSymbols211.svg#LigatureSymbols') format('svg'); 

    font-weight: normal; 
    font-style: normal; 
} 

production.rb

config.assets.paths << Rails.root.join('app', 'assets', 'fonts') 
config.assets.precompile += %w(.svg .eot .woff .ttf) 

但是,当我推到我的Heroku生产服务器我得到这个:

-----> Preparing app for Rails asset pipeline 
     Running: rake assets:precompile 
     I, [2013-05-06T06:21:07.804043 #2036] INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-c5b7db18fa0fcd910e92fee751776047.eot 
     I, [2013-05-06T06:21:07.809822 #2036] INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-09ff8be41a6bee98c834e9a278bb8b28.otf 
     I, [2013-05-06T06:21:07.812685 #2036] INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-1f682b1be252dbf6182d606a185b603f.svg 
     I, [2013-05-06T06:21:07.819262 #2036] INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-9e88765b872185b22e519da056cba9f0.ttf 
     I, [2013-05-06T06:21:07.829518 #2036] INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/LigatureSymbols211-a2d90ca6deff46bfcf9cade63d4902ce.woff 
     I, [2013-05-06T06:21:07.838351 #2036] INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/rails-5f9b3f343d9831cbf50b9bc980faf39b.png 
     I, [2013-05-06T06:21:17.072501 #2036] INFO -- : Writing /tmp/build_2snusxy9gm4d7/public/assets/application-6af5b81b9fcc820f1d43b4135f00317e.js 
     rake aborted! 
     undefined method `[]' for nil:NilClass 
     (in /tmp/build_2snusxy9gm4d7/app/assets/stylesheets/application.css) 

我想在我的application.css添加required线,但将不能工作。

编辑:

我可以在运行服务器时,我的开发机器上访问localhost:5000/assets/LigatureSymbols-2.11.eot。不知道这是否会有助于缩小什么错

编辑2:

代码工作与注释掉SCSS字体,是否有语法错误?

编辑3:

这是在跟踪堆栈的顶部:

.../sprockets-2.9.2/lib/sprockets/sass_functions.rb:63:in `sprockets_context' 
.../sprockets-2.9.2/lib/sprockets/sass_functions.rb:42:in `font_url' 

是有什么错我font-url电话?

EDIT 4:

从字体文件名和改变SCSS来体现,但同样的错误

移除破折号仍然存在

EDIT 5:

本地机器上生成的CSS:

@font-face { 
    font-family: LigatureSymbols; 
    src: font-url("LigatureSymbols211.eot"); 
    src: local("LigatureSymbols"), font-url("LigatureSymbols211.eot?#iefix") format("embedded-opentype"), font-url("LigatureSymbols211.woff") format("woff"), font-url("LigatureSymbols211.ttf") format("truetype"), font-url("LigatureSymbols211.svg#LigatureSymbols") format("svg"); 
    font-weight: normal; 
    font-style: normal; } 

回答

4

我发现了!奇怪的事情......可能是SASS中的一个错误。

如果我将代码直接放在我的application.css所需的文件home.css.scss中,则会发生错误。

此外,如果我将字体SCSS放在单独的文件(font.scss)和@import "font"中,它也会引发错误。

只有如果我需要我的application.css中的font.scss文件,资产管道会通过。

,如果我在application.css

+0

我在这里添加了一个不是很好的答案:http://stackoverflow.com/a/36539357/1965639 通过将font.scss更改为font.css并以不同方式包含它,我解决了该问题。 @迈克尔约翰斯顿指出我正确的方向。 – jjk 2016-04-11 19:09:54

0

将此添加到您的config/application.rb

config.assets.initialize_on_precompile = false 

我有类似的问题与Heroku,这有助于有时。 这是值得一试。让我知道这是否有帮助。

+0

这已经在我的'config/application.rb'感谢您的建议,虽然 – 2013-05-06 06:02:31

2

删除连字符。资产管道使用连字符来指纹资产并在字体路径中使用连字符导致问题。

+0

将文件重命名为'LigatureSymbols211'点任何和仍然会得到相同的错误。还是)感谢你的建议! – 2013-05-06 06:23:01

+0

你能访问期望的网址上的字体吗?即something.com/fonts/LigatureSymbols211.eot或something.com/LigatureSymbols211.eot – John 2013-05-06 06:35:45

+0

在我的本地机器/ dev服务器上,我可以在'/ assets/LigatureSymbols211.eot'和其他扩展中访问。在预编译中止之前,我在生产服务器上尝试使用指纹,但它不起作用 – 2013-05-06 06:48:34

2

我得到了完全相同的错误,当我忘了改从文件扩展名使用font-url(...) VS asset-url(...,font) VS url(asset-path(...,font))当包括字体,他们所有的工作通过=require它没有问题.css转换成.scss。这为我修好了。