Rake Tasks


Create Rake Tasks


Initial Setup

Creating rake tasks is an easy way to automate processes in rails. A sample rake task is found below. This specific tasks accepts two arguments, which are denoted using symbols in array format.

# lib/tasks/users.rake
require 'rake'

namespace :users do
  desc "Accepts a preset quantity of users to create along with an assigned role '[30, editor]'"
  task :add_users_with_role, [:qty, :role] => [:environment] do |t, args|
    args[:qty].to_i.times do |n|
...

Read Blog Post