LoginSignup
44
32

More than 5 years have passed since last update.

RailsでRakeタスクをconsoleから呼び出す方法

Last updated at Posted at 2014-06-21

Railsの開発ではconsole(というかdebugger)が必需品ですよね。

となると、当然、バッチ処理用に作るRakeタスクもconsoleでデバッグしたくなるわけで。
実はこれまで、consoleからはRakeタスクをキックできないと思っていたので、実際の処理をModel.execに書いてRakeタスクからはそれを呼ぶ形で書いてたんですが、調べたら簡単に出来ました。

consoleを起動した後
require 'rake'
Rails.application.load_tasks
Rake::Task['タスク名'].execute

なお、タスク名の部分は、namespaceを含んだ形で記述します。
例えば、inactive_user:destroy_suspendedのような形。

44
32
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
44
32