【问题标题】:Rails core module extension not loading when RAILS_ENV=production当 RAILS_ENV=production 时,Rails 核心模块扩展未加载
【发布时间】:2013-07-08 06:13:18
【问题描述】:

在 Rails 3.2.12 中,我正在尝试按照建议 here 向核心 Enumerable 模块添加一个方法,我正在使用 require_dependencyconfig.watchable_dirs 建议here。我的方法在开发服务器和控制台中运行良好,但是当我 rake assets:precompile 或尝试部署时,我得到 No such file to load -- lib/extensions/enumerable。为了从我的 lib 目录中适当地自动加载此方法,我缺少什么?

config/application.rb

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

lib/extensions/enumerable.rb

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

app/models/mymodel.rb

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

【问题讨论】:

    标签: ruby-on-rails-3.2 rails-engines activesupport


    【解决方案1】:

    我认为您的require_dependency 中的lib 是多余的:

    require_dependency 'extensions/enumerable.rb'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-19
      • 2014-09-12
      • 1970-01-01
      • 2014-04-06
      • 2016-07-10
      • 1970-01-01
      • 2021-02-27
      • 2014-11-22
      相关资源
      最近更新 更多