4

I'm creating a rails engine, which I have written some rake tasks in. My rake tasks call rake tasks in a 3rd-party gem, which I've included as a dependency in my gemspec.

When I try to run my rake tasks, it fails stating it cannot find the tasks from the 3rd party gem. Which makes senses considering Rake -T shows my tasks, but not the 3rd party's.

If I include the 3rd party gem in my application gemfile, everything is perfect, but I don't want to do this.

I'm guessing I need to add another include to my engine's rake_tasks do block, but no idea what to include. I've tried a variety of paths, but none seem to work.

tshepang
  • 12,111
  • 21
  • 91
  • 136
John Agan
  • 333
  • 4
  • 12

2 Answers2

2
# lib/my_gem.rb
module MyGem
  ROOT_PATH = File.expand_path "../../", __FILE__
  # :: before of the module name it is not to encapsulate the module "My Gem"
  module ::Rails
    class Application
      rake_tasks do
        Dir[File.join(ROOT_PATH, "/lib/tasks/", "**/*.rake")].each do |file|
          load file
        end
      end
    end
  end
end
rplaurindo
  • 1,277
  • 14
  • 23
1

Sounds like your third party gem may not have a railtie set up. The rake tasks from gems aren't automatically included within a Rails application. Here are two good resources which help explain how to set up a Rail tie, from which you can probably base some code to manually include the third party gem's rake tasks:

including rake tasks in gems

http://blog.nathanhumbert.com/2010/02/rails-3-loading-rake-tasks-from-gem.html

Community
  • 1
  • 1
Winston Kotzan
  • 1,979
  • 20
  • 25