首页 文章

Bootstrap 3 Glyphicon错误

提问于
浏览
5

我意识到这里已经回答了类似的问题,但很多答案都是使用宝石或直接修改Bootstrap的文件 . 虽然这些是有效的配置,但我想增加我在这个领域的知识集(链轮,Rails管道,一般的前端开发),并希望了解为什么这不起作用,底层问题是什么 .

Ruby 2.0.0-p353,Rails 4.0.2,Bootstrap 3.0.3,Nginx 1.4.4,Passenger 4.0.33

我从他们的网站下载了最新的Bootstrap zip,执行了所有发现的操作here将这些文件直接包含到我的应用程序中,并且能够让我的开发环境中的glyphicons完全按预期显示 . 但是,当我部署到 生产环境 环境时,glyphicons在Chrome中显示为正方形 . 我将glyphicons文件的各个文件扩展名添加到 生产环境 预编译中,并验证它们与glyphicon文件一起没有gzip压缩文件 .

production.rb:

config.assets.precompile = ['*.js', '*.css', '*.eot', '*.svg', '*.ttf', '*.woff']

我知道Rails在开发和 生产环境 之间加载资产的方式不同,但为什么不在 生产环境 中看到或理解glyphicon资产呢?有没有办法用我当前的配置解决这个问题,或者我是否需要更改我包含这些资产的方式以允许我修复此错误?

此外,在开发和 生产环境 中,每次渲染使用glyphicon的页面时,我都会收到以下错误,但图标仍会显示 . 这有关系吗?

  • ActionController :: RoutingError(没有路由匹配[GET] "/fonts/glyphicons-halflings-regular.woff")

  • ActionController :: RoutingError(没有路由匹配[GET] "/fonts/glyphicons-halflings-regular.ttf")

  • ActionController :: RoutingError(没有路由匹配[GET] "/fonts/glyphicons-halflings-regular.svg")

2 回答

  • 3

    您应该从站点手动手动下载 glyphicons fonts 并将其放在 app/assets/stylesheets/fonts 文件夹中 .

    还有一些问题尚未解决 bootstrap gem

    您可以参考以下链接

    Bootstrap 3 Glyphicons are not working

  • 0
    • config/application.rb 中,在 class Application < Rails::Application 之后添加以下内容 . 它应该如下所示:
    class Application < Rails::Application
        config.assets.paths << "#{Rails}/vendor/assets/fonts"
    
    • 在终端中,运行以下命令编译资产:
    rake assets:precompile RAILS_ENV=development
    
    • 通过将 @font-face 资源位置从 ../fonts/ 更改为 /assets/ 来编辑 bootstrap.css 文件 . 它应该如下所示:
    @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 重启,就会出现字形 .

相关问题