我想创建一个cron作业,在用户创建后每周发送邮件。
用户控制器
def create
@user = User.new(user_params)
if @user.save
redirect_to(@book, :notice => 'User created')
else
render 'new'
end
Mailer.send_mail(@user).deliver
end
Scheduler.rb
every :monday do
runner "Mailers.send_mail.deliver"
end
Mailers.rb
def send_mail(user)
@user = user
mail(to: @user.email, subject: 'your account has been created')
end
如何在用户创建后运行cron作业?