2016-04-29 49 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