2016-04-29 77 views
8

我越来越想在本地预编译我的资产链轮错误链轮:: NotImplementedError:自定义asset_path帮手未实现

RAILS_ENV=production bundle exec rake assets:precompile 

rake aborted! 
Sprockets::NotImplementedError: Custom asset_path helper is not implemented 

Extend your environment context with a custom method. 

    environment.context_class.class_eval do 
     def asset_path(path, options = {}) 
     end 
    end 
/Users/cman/.rvm/gems/[email protected]/gems/sprockets-3.6.0/lib/sprockets/context.rb:198:in `asset_path' 
/Users/cman/.rvm/gems/[email protected]/gems/sprockets-3.6.0/lib/sprockets/context.rb:218:in `font_path' 
/Users/cman/.rvm/gems/[email protected]/gems/font-awesome-rails-4.6.1.0/app/assets/stylesheets/font-awesome.css.erb:15:in `_evaluate_template' 

我不能为我的生命弄清楚为什么发生这种情况时,以下 - 任何建议如何解决将不胜感激!

更新

我能只有当我添加一个初始化具有以下预编译:

Rails.application.assets.context_class.class_eval do 
    def asset_path(path, options = {}) 
    return '' 
    end 
end 

但是,如果我这样做,当我推到我的分级环境中,glyphicons从引导有一个空的路径,因此不渲染:

font-face{font-family:'Glyphicons Halflings';src:url("");src:url("") format("embedded-opentype"),url("") format("woff"),url("") format("truetype"),url("") 

更新2

如果我修改初始化到下面,我得到一个路径在我的预编译的glypicons引导资产,但不预编译Glyphicon文件,它以非编译的资源路径:

Rails.application.assets.context_class.class_eval do 
    def asset_path(path, options = {}) 
    #return '' 
    "/assets/#{path}" 
    end 
end 

@font-face{font-family:'Glyphicons Halflings';src:url("/assets/bootstrap/glyphicons-halflings-regular.eot");src:url("/assets/bootstrap/glyphicons-halflings-regular.eot?#iefix") format("embedded-opentype"),url("/assets/bootstrap/glyphicons-halflings-regular.woff") format("woff"),url("/assets/bootstrap/glyphicons-halflings-regular.ttf") format("truetype"),url("/assets/bootstrap/glyphicons-halflings-regular.svg#glyphicons_halflingsregular") 

这是我Gemfile.lock的,因为它涉及到的资产/链轮宝石:

bootstrap-sass (3.1.1.0) 
     sass (~> 3.2) 
rails (4.2.5.2) 
     actionmailer (= 4.2.5.2) 
     actionpack (= 4.2.5.2) 
     actionview (= 4.2.5.2) 
     activejob (= 4.2.5.2) 
     activemodel (= 4.2.5.2) 
     activerecord (= 4.2.5.2) 
     activesupport (= 4.2.5.2) 
     bundler (>= 1.3.0, < 2.0) 
     railties (= 4.2.5.2) 
     sprockets-rails 
sass (3.2.19) 
    sass-rails (4.0.5) 
     railties (>= 4.0.0, < 5.0) 
     sass (~> 3.2.2) 
     sprockets (~> 2.8, < 3.0) 
     sprockets-rails (~> 2.0) 
+1

你能分享一个最小工作示例显示问题的完整源代码?一个git回购,例如。 – smathy

+0

您是否按照文档中的说明导入了自动推进链轮? https://github.com/twbs/bootstrap-sass#a-ruby-on-rails –

+0

我认为Glyphicon问题只是我指定自定义'asset_path'初始值设定项的一个症状。我真正需要弄清楚的是为什么它要求这样做。如果我创建一个全新的应用程序,它不会要求预编译。 – cman77

回答

1

您可以轻松解决这个问题。尽管您当前的问题更多是与版本相关的问题,但不确定是否正确捆绑更新。但有其他解决方案。尝试安装以下宝石:

https://github.com/petebrowne/sprockets-helpers

+0

我不要认为增加另一个宝石是答案。正如我所说的,我能够在不需要任何自定义资产助手的情况下,一个接一个地从我那里重新推出我的产品回购协议。 – cman77

+0

我能够重现问题并添加链轮 - 助手宝石确实可以解决此问题。任何有关我为什么突然需要它的见解? – cman77

1

我建议,认为主要问题是sprockets版本。在我的rails 4.2.6项目中我使用了sprockets 3.6.0,并且在你的Gemfile.lock片段中使用了< 3.0版本。

就像一个测试,你可以更新导轨到4.2.6并尝试新鲜链轮3.6.0 +链轮导轨3.0.1和新鲜sass-rails 5.0.4sass 3.4.22宝石。我真的不知道哪一个更新会有帮助,但是,我认为它应该起作用。

+0

我实际上已经尝试过。我将链轮,链轮,导轨,sass-rails,sass升级到最新的宝石。 – cman77

1

我不知道这是否符合答案或不是,但我结束了只是拉下我的生产Heroku回购和确认一切预编译。然后,我慢慢升级了所有的宝石,并继续正确预编译。我想我永远不会知道是什么造成了这种情况。感谢那些贡献。

+0

我走了一条类似的混淆道路或删除和添加的东西,但事实证明,我得到这个错误的原因是因为我在初始化程序全局'#include ActionView :: Helpers :: AssetUrlHelper': -/ – mraaroncruz