2015-02-24 69 views
0

,我发现了以下错误在Heroku的:的Heroku:ActionController的:: RoutingError(无路由匹配[GET]“/fonts/glyphicons-halflings-regular.ttf)

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

当服务器尝试找到引导的halflings images来自供应商的资产:

当我用彪马和福尔曼在本地运行的应用程序,那么它的那些半身人的图像显示工作正常

Heroku的日志如下所示:

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文件

/* 
* 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文件:

{ 
    "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 
} 

这些半身人可以在两个文件夹在我的项目中找到: vendor/assets/bower_components/bootstrap/dist/fonts vendor/assets/bower_components/bootstrap/fonts

除了这些半身人的图像,应用程序工作正常:

enter image description here

我以前删除public/assets目录提交并重新部署到Heroku上,这解决了我的大问题https://stackoverflow.com/a/28681947/2048391感谢史蒂夫。旧版问题(当导航栏没有出现时)中的错误信息与此类似,所以这个问题也可能与资产有关。

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

已部署到Heroku上的代码可以在GitHub

回答

7

发现你有几个问题在这里。

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

解决方案

  1. 使用官方的引导,萨斯凉亭包,这将引导编译使用正确的字体路径。

    安装亭子,青菜和删除香草引导:

    bower uninstall bootstrap --save 
    bower install bootstrap-sass --save 
    
  2. 移动application.cssapplication.css.scss。在mainfest部分之后添加以下几行。

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

    因为非sass的bootstrap版本被删除,您还必须确保删除此行。

    *= require bootstrap/dist/css/bootstrap 
    
  3. 将出售资产路径添加到application.rb,以便rails可以编译和提供它们。

    您的application.rb需要更新,以便Rails知道资产的存在位置。每官方引导,SASS文件(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 
    

这应该可以解决这个问题,你glyphicons应该现在载入。

+0

非常感谢!它的工作原理:-)优秀! – jyrkim 2015-02-28 09:51:18

相关问题