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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)