I've created a Rake Task for a Mailer to later scheduled wth Crontab and automate with Gem Whenever for send a email to a users. For a while is a just a test to know if task is working.
My Rake Task and Mailer is the following.
require 'rake'
desc 'send digest email'
task send_warn_course: :environment do
MailCourseWarnMailer.course_available(user).deliver!
end
# And my Mailer is:
class MailCourseWarnMailer < ActionMailer::Base
def course_available(user)
@user = user
mail(to: @user.email, subject: "Curso disponível")
end
end
I passed the parameters to task but this is not working. When I run rake send_warn_course I get the error:
rake send_warn_course
rake aborted!
NameError: undefined local variable or method `user' for main:Object
Anyone knows what is happening? What did I miss here?