2013-07-08 48 views
1

在Rails 3.2.12,我試圖的方法添加到核心Enumerable模塊所建議here,並且我使用require_dependencyconfig.watchable_dirs所建議here。我的方法在開發服務器和控制檯中工作正常,但當我rake assets:precompile或試圖部署時,我得到No such file to load -- lib/extensions/enumerable。我錯過了什麼,適當自動從我的lib目錄中自動加載此方法?Rails的核心模塊的擴展不加載時RAILS_ENV =生產

的config/application.rb中

... 
module Myapp 
    class Application < Rails::Application 
    ... 
    config.watchable_dirs['lib/extensions'] = [:rb] 
    end 
end 
... 

的lib /擴展/ enumerable.rb

module Enumerable 
    def each_with_previous 
    self.inject(nil){|prev, curr| yield prev, curr; curr} 
    self 
    end 
end 

應用程序/模型/ mymodel.rb

class Mymodel 
    ... 
    require_dependency 'lib/extensions/enumerable.rb' 
    ... 
end 

回答

1

我想在你的require_dependencylib是多餘的:

require_dependency 'extensions/enumerable.rb' 
+0

哇,謝謝。這根本不令人尷尬。 –