Heroku:ActionController :: RoutingError(没有路由匹配[GET]" /fonts/glyphicons-halflings-regular.ttf) [英] Heroku: ActionController::RoutingError (No route matches [GET] "/fonts/glyphicons-halflings-regular.ttf)

查看:300
本文介绍了Heroku:ActionController :: RoutingError(没有路由匹配[GET]" /fonts/glyphicons-halflings-regular.ttf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

当服务器试图找到Bootstrap的。旧版问题(当导航栏没有出现时)中的错误信息与此类似,所以这个问题也可能与资产有关。

如果您的问题听起来很熟悉,那么请删除一行。非常感谢: - )

部署到Heroku的代码可以在 GitHub

解决方案

这里有几个问题。




  • 字体资源不在链轮已知的路径中,因此在资产编译打开时(即生产),它们不会被提供。 / li>
  • 即使您修复了资产编译,您也正在使用bootstrap.css的静态版本,因此无法将字体资产的路径设置为与Rail放置它们的位置相匹配。
  • >


解决方案
$ b


  1. 使用正式的bootstrap-sass bower软件包,它将用适当的字体路径编译bootstrap。



    安装bower-sass并删除vanilla bootstrap:

      bower卸载bootstrap --save 
    bower install bootstrap-sass --save


  2. application.css 移至 application.css.scss

      $ icon-font-path:bootstrap-sass / assets / fonts / bootstrap /; 
    @importbootstrap-sass / assets / stylesheets / bootstrap-sprockets;
    @importbootstrap-sass / assets / stylesheets / bootstrap;

    您必须确保在删除非sass的bootstrap版本后删除此行。 / p>

      * =需要bootstrap / dist / css / bootstrap 


  3. 将自定义资产路径添加到application.rb,以便rails可以编译和提供它们。 .rb也需要更新,以便Rails知道资产的存在位置。根据官方bootstrap-sass文档( https://github.com/twbs/bootstrap-sass#c-bower
    $ b $ pre $资产路径
    root.join('vendor','assets',' bower_components')。to_s.tap do | bower_path |
    config.sass.load_paths<< bower_path
    config.assets.paths<< bower_path
    结束
    #预编译引导程序字体
    config.assets.precompile<< %b(bootstrap-sass / assets / fonts / bootstrap / [\w-] + \。(?: eot | svg | ttf | woff2?)$)
    #所需的最小Sass数精度bootstrap- sass
    :: Sass :: Script :: Number.precision = [8,:: Sass :: Script :: Number.precision] .max



  4. 这应该可以解决问题,现在应该加载您的图标。


    I’m getting the following error at Heroku:

    ActionController::RoutingError (No route matches [GET] "/fonts/glyphicons-halflings-regular.ttf)
    

    when the server is trying to find Bootstrap’s halflings images from vendor assets:

    When I run the app by using Puma and Foreman locally, then it’s working fine as those halfling images appear.

    Heroku log is shown below:

    2015-02-24T06:15:45.302830+00:00 app[web.1]: source=rack-timeout id=983308e6-3d6f-494b-b8e1-f37b39b14d42 wait=11ms timeout=20000ms service=2ms state=completed
    2015-02-24T06:15:45.302416+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/puma-2.11.1/lib/puma/server.rb:375:in `process_client'
    2015-02-24T06:15:45.304253+00:00 heroku[router]: at=info method=GET path="/fonts/glyphicons-halflings-regular.woff" host=fathomless-sands-8666.herokuapp.comrequest_id=983308e6-3d6f-494b-b8e1-f37b39b14d42 fwd="212.149.201.185" dyno=web.1 connect=6ms service=6ms status=404 bytes=1531
    2015-02-24T06:15:45.506425+00:00 heroku[router]: at=info method=GET path="/fonts/glyphicons-halflings-regular.ttf" host=fathomless-sands-8666.herokuapp.comrequest_id=41275bad-2ed7-4cfd-89c5-d223b6063d62 fwd="212.149.201.185" dyno=web.1 connect=28ms service=37ms status=404 bytes=1531
    2015-02-24T06:15:45.476848+00:00 app[web.1]: Started GET "/fonts/glyphicons-halflings-regular.ttf" for 212.149.201.185 at 2015-02-24 06:15:45 +0000
    2015-02-24T06:15:45.478340+00:00 app[web.1]: 
    2015-02-24T06:15:45.478344+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/fonts/glyphicons-halflings-regular.ttf"):
    2015-02-24T06:15:45.478347+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
    2015-02-24T06:15:45.471994+00:00 app[web.1]: source=rack-timeout id=41275bad-2ed7-4cfd-89c5-d223b6063d62 wait=33ms timeout=20000ms state=ready
    2015-02-24T06:15:45.478349+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
    2015-02-24T06:15:45.478351+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:38:in `call_app'
    2015-02-24T06:15:45.478353+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:20:in `block in call'
    2015-02-24T06:15:45.478355+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:67:in `block in tagged'
    

    application.css file

    /*
     * This is a manifest file that'll be compiled into application.css, which will include all the files
     * listed below.
     *
     * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
     * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
     *
     * You're free to add application-wide styles to this file and they'll appear at the top of the
     * compiled file, but it's generally better to create a new file per style scope.
     *= require bootstrap/dist/css/bootstrap
     *= require_self
     *= require_tree .
     */
    

    .bower.json file:

    {
      "name": "bootstrap",
      "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.",
      "version": "3.3.2",
      "keywords": [
        "css",
        "js",
        "less",
        "mobile-first",
        "responsive",
        "front-end",
        "framework",
        "web"
      ],
      "homepage": "http://getbootstrap.com",
      "main": [
        "less/bootstrap.less",
        "dist/css/bootstrap.css",
        "dist/js/bootstrap.js",
        "dist/fonts/glyphicons-halflings-regular.eot",
        "dist/fonts/glyphicons-halflings-regular.svg",
        "dist/fonts/glyphicons-halflings-regular.ttf",
        "dist/fonts/glyphicons-halflings-regular.woff"
      ],
      "ignore": [
        "/.*",
        "_config.yml",
        "CNAME",
        "composer.json",
        "CONTRIBUTING.md",
        "docs",
        "js/tests",
        "test-infra"
      ],
      "dependencies": {
        "jquery": ">= 1.9.1"
      },
      "_release": "3.3.2",
      "_resolution": {
        "type": "version",
        "tag": "v3.3.2",
        "commit": "bcf7dd38b5ab180256e2e4fb5da0369551b3f082"
      },
      "_source": "git://github.com/twbs/bootstrap.git",
      "_target": "~3.3.2",
      "_originalSource": "bootstrap",
      "_direct": true
    }
    

    Those halflings can be found in two folders in my project: vendor/assets/bower_components/bootstrap/dist/fonts vendor/assets/bower_components/bootstrap/fonts

    Apart from those halfling images, the app is working fine:

    I have previously removed public/assets directory committed and redeployed to Heroku, which solved my older problem https://stackoverflow.com/a/28681947/2048391 thanks to Steve. The error message in the older issue (when the navbar didn’t appear) was quite similar to this one, so this issue might have something to do with assets as well.

    If the issue sounds familiar to you, then please drop a line. Many thanks :-)

    The code that was deployed to Heroku can be found at GitHub

    解决方案

    You have a couple of issues here.

    • The font assets aren't in a path known to the sprockets so they won't be served when asset compilation is on (i.e., production).
    • Even if you fixed asset compilation, you are using a static version of bootstrap.css so the path to the font assets can't be set to match where rails will place them.

    Solution:

    1. Use the official bootstrap-sass bower package which will compile bootstrap with the proper font paths.

      Install bower-sass and remove vanilla bootstrap:

        bower uninstall bootstrap --save
      bower install bootstrap-sass --save
      

    2. Move application.css to application.css.scss. Add the following lines after the mainfest section.

      $icon-font-path: "bootstrap-sass/assets/fonts/bootstrap/";
      @import "bootstrap-sass/assets/stylesheets/bootstrap-sprockets";
      @import "bootstrap-sass/assets/stylesheets/bootstrap";
      

      You must also make sure to remove this line since the non-sass version of bootstrap was removed.

      *= require bootstrap/dist/css/bootstrap
      

    3. Add the vendored assets paths to application.rb so that rails can compile and serve them.

      You application.rb needs to be updated as well so that Rails knows where the assets live. Per the official bootstrap-sass documentation (https://github.com/twbs/bootstrap-sass#c-bower):

      # Bower asset paths
      root.join('vendor', 'assets', 'bower_components').to_s.tap do |bower_path|
        config.sass.load_paths << bower_path
        config.assets.paths << bower_path
      end
      # Precompile Bootstrap fonts
      config.assets.precompile << %r(bootstrap-sass/assets/fonts/bootstrap/[\w-]+\.(?:eot|svg|ttf|woff2?)$)
      # Minimum Sass number precision required by bootstrap-sass
      ::Sass::Script::Number.precision = [8, ::Sass::Script::Number.precision].max
      

    This should resolve the problem and your glyphicons should be loading now.

    这篇关于Heroku:ActionController :: RoutingError(没有路由匹配[GET]&quot; /fonts/glyphicons-halflings-regular.ttf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆