如果他们未在48小时内激活,我想向用户重新发送激活电子邮件。我曾经使用过gem,但它没有发送电子邮件。即使动作邮件工作正常,并在用户注册时发送电子邮件 的 schedule.rb
set :environment, :development
every 1.minutes do
runner "user.resend_account_activation"
end
user_mailer.rb
def resend_account_activation
@user = User.where('activated = ?',false && 'activated_at < ?',48.hours.ago)
mail to: @user.email, subject: "You forgot to activate"
end
user.rb
def resend_account_activation
# @outdated_users = User.where('activated_at < ?',30.seconds.ago)
UserMailer.resend_account_activation.deliver_now!
end
在我的cmd中
# Begin Whenever generated tasks for: store
* * * * * /bin/bash -l -c 'cd /mnt/c/Sites/testApp && bin/rails runner -e production '\''user.resend_account_activation'\'''
# End Whenever generated tasks for: store
答案 0 :(得分:0)
我认为不应该是user.resend_account_activation
会是这样的
user.rb
def self.resend_account_activation_to_users
User.where('activated = ? AND activated_at < ?', false ,48.hours.ago).each do |user|
UserMailer.resend_account_activation(user.id).deliver_now!
end
end
注意:我已经更改了48小时的查询。请在执行前检查
user_mailer.rb
def resend_account_activation(user_id)
@user = User.find(user_id)
mail to: @user.email, subject: "You forgot to activate"
end
runner "User.resend_account_activation" # Note: changed user => User