没有在Rails 4 app中预编译的Glyphicons

时间:2022-11-10 20:37:40

I am writing a Rails 4 app using Twitter bootstrap (the sass version, with files copied directly into my assets directory rather than using a gem). Glyphicons work in development but in production are displayed as squares. I believe this is because they are not being appropriately precompiled and delivered by the asset pipeline.

我正在使用Twitter bootstrap编写一个Rails 4应用程序(sass版本,文件直接复制到我的资产目录而不是使用gem)。 Glyphicons在开发中工作,但在生产中显示为正方形。我相信这是因为资产管道没有对它们进行适当的预编译和交付。

I have tried adding the following to production.rb without success:

我尝试将以下内容添加到production.rb但没有成功:

config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/

Can anyone suggest a solution to this?

有谁能建议解决这个问题?

Many thanks

1 个解决方案

#1


0  

The reason you're having difficulties is because your regular expression does not actually match the path names of your fonts. One way going about this is to change your regular expression to match the full path.

您遇到困难的原因是因为您的正则表达式实际上与您的字体的路径名不匹配。解决此问题的一种方法是更改​​正则表达式以匹配完整路径。

config.assets.precompile << /.+\.(?:svg|eot|woff|ttf)$/i

On the other hand, regular expressions are not always very readable for other users diving in to your code base and can easily get out of hand. In this case we can a more apt tool for the job, the glob syntax

另一方面,对于潜入代码库的其他用户而言,正则表达式并不总是非常易读,并且很容易失控。在这种情况下,我们可以为作业提供更合适的工具,即glob语法

config.assets.precompile += %w( *.svg *.eot *.woff *.ttf )

#1


0  

The reason you're having difficulties is because your regular expression does not actually match the path names of your fonts. One way going about this is to change your regular expression to match the full path.

您遇到困难的原因是因为您的正则表达式实际上与您的字体的路径名不匹配。解决此问题的一种方法是更改​​正则表达式以匹配完整路径。

config.assets.precompile << /.+\.(?:svg|eot|woff|ttf)$/i

On the other hand, regular expressions are not always very readable for other users diving in to your code base and can easily get out of hand. In this case we can a more apt tool for the job, the glob syntax

另一方面,对于潜入代码库的其他用户而言,正则表达式并不总是非常易读,并且很容易失控。在这种情况下,我们可以为作业提供更合适的工具,即glob语法

config.assets.precompile += %w( *.svg *.eot *.woff *.ttf )