2017-04-03 83 views
0

我試圖通過我的用戶誰是經理,併發送給他們所有的電子郵件,但我收到以下錯誤:undefined method "email" for nil:NilClass。這就是我如何循環,我認爲這是問題的根源:通過用戶循環發送電子郵件

def send_manager_email(current_user) 
    managers = User.where(manager: true) 
    managers.each do |manager| 
    UserMailer.timesheet_notification(@manager, current_user).deliver_now 
    end 
end 

,這是我的郵件:

def timesheet_notification(user, current_user) 
    @greeting = "Hi" 
    @current_user = current_user 
    mail to: user.email, subject: "New Timesheet" 
end 

我要去哪裏錯了?

回答

1

請試試這個。您不需要@manager,傳遞參數時只能使用manager

def send_manager_email(current_user) 
     managers = User.where(manager: true) 
     managers.each do |manager| 
     UserMailer.timesheet_notification(manager, current_user).deliver_now 
     end 
    end 

,這是我的郵件:

def timesheet_notification(user, current_user) 
    @greeting = "Hi" 
    @current_user = current_user 
    mail to: user.email, subject: "New Timesheet" 
end 

希望這會爲你工作。謝謝!

+0

那麼,這是愚蠢的我...非常感謝!將盡快接受。 – CodeBoy

+0

好的,沒問題!請接受我的回答。如果它在爲你工作。 –