Rake -T がタスクを識別しない
概要
Rake タスク (レールなし) をセットアップしようとしているので、デモの Hello World タスクを作成しました。ただし、 rake -T または rake –tasks を実行すると、タスクが識別されていないかのように、何も返されません。ここで私は何を間違っているのでしょうか?
また、rake hello_world を実行すると、次のエラーが表示されます。
➜ ~/GitHub/Cerner/test git:(master) ✗ rake hello_world
rake aborted!
Don't know how to build task 'hello_world' (See the list of available tasks with `rake --tasks`)
/usr/share/rvm/gems/ruby-2.6.6/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/home/hsbagga28/gems/bin/ruby_executable_hooks:22:in `eval'
/home/hsbagga28/gems/bin/ruby_executable_hooks:22:in `<main>'
(See full trace by running task with --trace)
[更新] rakefile:
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
$LOAD_PATH.push File.expand_path('lib', __dir__)
解決策
結局、デフォルトの Rakefile を次のように作成しました。
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative "config/application"
Rails.application.load_tasks
この後、rake -T は lib/tasks で定義されたタスクを返したようです