Question

In Rails 3.2.12, I am trying to add a method to the core Enumerable module as suggested here, and I am using require_dependency and config.watchable_dirs as suggested here. My method works fine in development server and console, but when I rake assets:precompile or attempt to deploy I get No such file to load -- lib/extensions/enumerable. What piece am I missing to appropriately autoload this method from my lib directory?

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
Was it helpful?

Solution

I think the lib in your require_dependency is extraneous:

require_dependency 'extensions/enumerable.rb'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top