[英]Rails 3.2.6 routing error for fonts
I have a Rails 3.2.6 based application using web-app-theme gem. 我有一个使用web-app-theme gem的基于Rails 3.2.6的应用程序。 After deploying in production I seeing following errors in
/var/log/apache2/error.log
. 在生产环境中部署后,我在
/var/log/apache2/error.log
看到以下错误。
[Wed Jul 18 23:00:14 2012] [error] [client 50.53.58.188] Premature end of script headers: fonts, referer: https://xxx.xxx.xx.xxx
[ pid=8920 thr=139857209571072 file=ext/apache2/Hooks.cpp:819 time=2012-07-18 23:00:14.743 ]: The backend application (process 9474) did not send a valid HTTP response; instead, it sent nothing at all. It is possible that it has crashed; please check whether there are crashing bugs in this application.
[ pid=9474 thr=9488700 file=utils.rb:176 time=2012-07-18 23:00:14.744 ]: *** Exception ActionController::RoutingError in application (No route matches [GET] "/assets/fonts/museosans_500-webfont.svg") (process 9474, thread #<Thread:0x00000001219278>):
from /usr/lib/ruby/gems/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/middleware/show_exceptions.rb:53:in `call'
from /usr/lib/ruby/gems/1.9.1/gems/railties-3.1.3/lib/rails/rack/logger.rb:13:in `call'
from /usr/lib/ruby/gems/1.9.1/gems/rack-1.3.6/lib/rack/methodoverride.rb:24:in `call'
from /usr/lib/ruby/gems/1.9.1/gems/rack-1.3.6/lib/rack/runtime.rb:17:in `call'
from /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
.....
I have placed the mentioned file museosans_500-webfont.svg
in app/assets/fonts/
directory. 我已将提到的文件
museosans_500-webfont.svg
放在app/assets/fonts/
目录中。 But why I am still this error. 但是为什么我还是这个错误。 I also see similar error for other assets like
/assets/fonts/museosans_500-webfont.ttf
, etc. 对于其他资产,例如
/assets/fonts/museosans_500-webfont.ttf
等,我也看到类似的错误。
Any feedback is much appreciated. 任何反馈都非常感谢。 Thanks.
谢谢。
-- Atarangp -阿塔朗普
Try add fonts dir to assets path in environment.rb: 尝试将fonts dir添加到environment.rb中的资产路径:
config.assets.enabled = true
config.assets.paths << "#{Rails.root}/app/assets/fonts"
The url in your CSS / HTML seems to be wrong: 您的CSS / HTML中的网址似乎是错误的:
/assets/fonts/museosans_500-webfont.svg
You should change that to: 您应该将其更改为:
/assets/museosans_500-webfont.svg
But keep the file on the app/assets/fonts
directory. 但是将文件保留在
app/assets/fonts
目录中。
I ran into the same problem when integrating the Katex library. 集成Katex库时遇到了相同的问题。
The issue is that Rails' Asset Pipeline compiles the assets into the public/assets
directory without keeping the fonts
or images
or javascript
directories. 问题在于,Rails的资产管道将资产编译到
public/assets
目录中,而不保留fonts
, images
或javascript
目录。
So when you're looking for /assets/fonts/museosans_500-webfont.svg
, it doesn't exist, that font has been compiled to /assets/museosans_500-webfont.svg
. 因此,当您寻找
/assets/fonts/museosans_500-webfont.svg
,该字体不存在,该字体已编译为/assets/museosans_500-webfont.svg
。
To solve this you have two options: 要解决此问题,您有两种选择:
Update the path in the CSS or JS: 更新CSS或JS中的路径:
/assets/fonts/museosans_500-webfont.svg
becomes 变成
/assets/museosans_500-webfont.svg
Put the fonts in a fonts
subdirectory: 将字体放在
fonts
子目录中:
If you don't want to (or can't) update the CSS or JS (eg it's a minified third party library), then you can use the following method to ensure that there is a public/assets/fonts
directory that contains all your fonts. 如果您不想(或无法)更新CSS或JS(例如,这是一个缩小的第三方库),则可以使用以下方法来确保存在一个
public/assets/fonts
目录,其中包含所有您的字体。
Simply put your font(s) in the following path: 只需将您的字体放在以下路径中:
/assets/fonts/fonts/museosans_500-webfont.svg
Now your public/assets
directory will contain a fonts
directory and your GET request will be happy. 现在,您的
public/assets
目录将包含一个fonts
目录,并且您的GET请求将很高兴。
For more details see this answer . 有关更多详细信息,请参见此答案 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.