Rails Rake Task – Access to model class

You’re close 🙂

#lib/tasks/defaultuser.rake
require 'rake'
namespace :defaultuser do
  task :adduser => :environment do
    ...
  end

Note the use of :environment, which sets up the necessary Rails environment prior to calling the rake task. After that, your User object will be in scope.

Leave a Comment