Railtie and Rake Tasks

When developing a plugin gem and trying to add a rake task into Railtie, note the following:

  1. If your rake task has a .rake extension, make sure you ‘load’ instead of ‘require’.
  2. If your rake task is located at a different directory use Dir[File.join]
# lib/gemname/railtie.rb
module GemName
  class Railtie < Rails::Railtie
    rake_tasks do
      Dir[File.join(File.dirname(__FILE__),'../tasks/*.rake')].each { |f| load f }

Some cool resource