2017-08-03 67 views
1

我想重新發送一封激活郵件給用戶,如果他們沒有在48小時內激活它。我使用每當寶石,但它不發送電子郵件。即使行動郵件工作正常,併發送一封電子郵件,當用戶註冊 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 

I ñ我的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

我覺得這不應該是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

+0

我不知道這個查詢。 'User.where('activated =?',false &&'activated_at <?',48.hours.ago)' –

相關問題