1

I'm trying to create a gem plugin with a rake task. I just commented out pre-generated file in tasks folder but when I run rake my_plugin, error came out that

Don't know how to build task...

here is tasks/my_plugin.rake file

desc "Explaining what the task does"
task :my_plugin do
  # Task goes here
end
Cụt Cánh
  • 375
  • 2
  • 10

2 Answers2

0

You run rake myplugin, but define task :my_plugin. You miss the underscore.

shlajin
  • 1,416
  • 10
  • 23
0

You need to load the custom tasks in your plugin's Railtie:

module MyPlugin
  class Railtie < ::Rails::Railtie
    rake_tasks do
      load 'tasks/my_plugin.rake'
    end
  end
end

https://api.rubyonrails.org/classes/Rails/Railtie.html

user1032752
  • 751
  • 1
  • 11
  • 28