我正在尝试在我的 Rails 4 应用程序中使用 Bootstrap 3。已关注this使用 bootstrap saas 设置 bootstrap 3 的教程thisgithub 页面。
Bootstrap 工作正常,但字形图标未按预期工作。
某些字形根本不显示。例如我厌倦了在我的 application.html.erb 中显示其中一些以进行测试:
glyphicon glyphicon-floppy-disk -> <span class="glyphicon glyphicon-floppy-disk"></span>
</br>
glyphicon glyphicon-plus -> <span class="glyphicon glyphicon-plus"></span>
</br>
glyphicon glyphicon-minus -> <span class="glyphicon glyphicon-minus"></span>
图标呈现如下this
软盘图标根本不显示(显示无效字符)
加号和减号不是粗体,并且比引导程序网站上显示的小得多。
我还在 Rails 控制台上看到以下消息。
Started GET "/fonts/glyphicons-halflings-regular.woff" for 127.0.0.1 at 2014-02-22 16:29:54 -0800
ActionController::RoutingError (No route matches [GET] "/fonts/glyphicons-halflings-regular.woff"):
Started GET "/fonts/glyphicons-halflings-regular.ttf" for 127.0.0.1 at 2014-02-22 16:29:54 -0800
ActionController::RoutingError (No route matches [GET] "/fonts/glyphicons-halflings-regular.ttf"):
Started GET "/fonts/glyphicons-halflings-regular.svg" for 127.0.0.1 at 2014-02-22 16:29:54 -0800
ActionController::RoutingError (No route matches [GET] "/fonts/glyphicons-halflings-regular.svg"):
我非常感谢您对这个问题的意见。
Thanks!
我有同样的问题并找到了解决方案。全部功劳归于埃里克·明克尔,他写了一篇关于该主题的详细博客文章。我强烈建议阅读它以进行进一步的推理。
-
Edit app/assets/stylesheets/application.css
通过增加:
*= require bootstrap
-
Edit app/assets/javascripts/application.js
通过增加:
//= require bootstrap
-
In config/application.rb
,在后面添加以下内容class Application < Rails::Application
。它应该看起来像这样:
class Application < Rails::Application
config.assets.paths << "#{Rails}/vendor/assets/fonts"
-
在终端中,通过运行以下命令来编译您的资产:
rake assets:precompile RAILS_ENV=development
-
编辑bootstrap.css
通过更改文件@font-face
资源位置来自../fonts/
to /assets/
。它应该看起来像这样:
@font-face {
font-family: 'Glyphicons Halflings';
src: url('/assets/glyphicons-halflings-regular.eot');
src: url('/assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('/assets/glyphicons-halflings-regular.woff') format('woff'), url('/assets/glyphicons-halflings-regular.ttf') format('truetype'), url('/assets/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg');
}
你完成了。只需重新启动rails s
并且字形应该出现。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)