0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Rails】rake taskの使い方

Posted at

rake taskとは?

実行したい処理を記述しておき、rake taskコマンドを利用して実行できます。
複雑な処理をタスク化しておくことで、簡潔なコマンドで実行できるため便利です。

rake taskの作成方法

以下のコマンドを実行して、taskファイルを生成します。

$ rails g task

namespace :test_task do
  desc 'テストタスク' # 実行したいタスクの説明
  task :nothing do
  end
end

DBにデータを登録するなどの場合は、:environmentと記述します。

namespace :insert_user do
    desc 'ユーザー登録タスク'
    task aaa :environment do
        User.create(name: '花子', age: 18)
    end

参考文献

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?