【问题标题】:Glyphicons not properly precompiling in Production Rails在生产 Rails 中未正确预编译 Glyphicons
【发布时间】:2014-02-01 22:13:03
【问题描述】:

在使用 Rails 4 时,我遇到了一个问题,即来自 Bootstrap 的字形图标没有被正确预编译。生成如下:

started GET "/assets/glyphicons-halflings-white-ed38e147e3f6e976c0a7ad59e4d628f3.png" for          127.0.0.1 at 2014-01-13 18:41:25 -0500
Started GET "/assets/glyphicons-halflings-white-ed38e147e3f6e976c0a7ad59e4d628f3.png" for 127.0.0.1 at 2014-01-13 18:41:25 -0500
Processing by ApplicationController#routing_error as PNG
Processing by ApplicationController#routing_error as PNG
  Parameters: {"path"=>"assets/glyphicons-halflings-white-ed38e147e3f6e976c0a7ad59e4d628f3"}
  Parameters: {"path"=>"assets/glyphicons-halflings-white-ed38e147e3f6e976c0a7ad59e4d628f3"}
  Rendered public/404.html (0.3ms)
  Rendered public/404.html (0.3ms)
Completed 404 Not Found in 17ms (Views: 3.4ms | ActiveRecord: 8.0ms)
Completed 404 Not Found in 17ms (Views: 3.4ms | ActiveRecord: 8.0ms)

它在开发中运行良好。如果我在 production.rb 中设置 config.assets.compile = true 它似乎工作正常 - 但我知道根据这个 SO question 这是非常糟糕的: files produced by asset:precompile don't match urls generated by stylesheet_link_tag (missing digest) in minimal rails 4 site

在 Rails 3.2 中这对我来说不是问题。

任何帮助将不胜感激!

【问题讨论】:

    标签: twitter-bootstrap heroku ruby-on-rails-4


    【解决方案1】:

    将应用程序从 Rails 3.2 升级到 4 时,我遇到了同样的问题。

    生产应用托管在 Heroku 上

    在 Rails 3.2 中一切正常

    但是,在 Rails 4 中,Glyphs 在 Dev 中显示良好,但在生产中却没有。快速检查浏览器控制台显示 404,因为资产路径错误。

    在我的情况下,我需要

    config.assets.precompile += [
            'twitter/bootstrap/glyphicons-halflings.png',
            'twitter/bootstrap/glyphicons-halflings-white.png'
          ]
    

    【讨论】:

      【解决方案2】:

      添加

      config.assets.precompile += [
              'glyphicons-halflings.png',
              'glyphicons-halflings-white.png'
            ]
      

      在我的 application.rb 中修复了这个问题。

      我不确定为什么 Rails 4 和 Rails 3.2 需要这样做?

      【讨论】:

      • 您好 cman77,感谢您发布此答案!这对我很有效。您能否解释一下为什么要包含 PNG 文件,更重要的是,您是如何知道要包含 PNG 的?我只看到我的预编译生成的svgeotwoffttf 文件。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-05
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 1970-01-01
      • 2014-07-12
      相关资源
      最近更新 更多