4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rails consoleでrake taskを呼び出す

Last updated at Posted at 2021-07-19

デバッグやバッチ処理内でRake taskを呼び出したいときの対応

Rails.application.load_tasks
Rake::Task['my_task'].execute
# 引数を渡す
Rake::Task['my_task'].execute('arg_string')
Rake::Task['my_task'].execute(hoge: 'moge')

my_task には hoge:moge など rake hoge:moge と指定する名前が入ります。
他サンプルだと require 'rake' しているものもありますが rails c で入っている分には不要でした。


※こちらの記事は自ブログからの転載です

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?