2011-04-11 5 views
0

이메일 목록이 있습니다. 그리고 나는 각 사용자가 이메일을 수신 할 필요가있다. 이메일을 보낼 때 도움이 필요합니다.

그래서 만든 :

script/generate mailer Notifier 
다음

. app/views/notifier/newgrants_notification.erb 에서

class Notifier < ActionMailer::Base 
    def newgrants_notification(respondent) 
    recipients user.email 
    from  "[email protected]" 
    subject "Hi!" 
    body  (:respondent => respondent) 
    end 
end 

썼다 : Hello!

내가 질문을 내가 무슨 짓을했는지 실수

@question = Question.create(:text => params[:question][:text], :security => rand(888).to_i) 

if success = @question.save 
    respondents = Respondent.find(:all) 
    respondents.each do |res| 
    Inquiry.create(:question_id=>@question.id.to_i, :respondent_id=>res.id.to_i) 
    Notifier.newgrants_notification(respondents).deliver #this is right?? 
    end 

을 만들이 내 컨트롤러? 메시지가 오지 않습니다 (

답변

4

HI를 볼 경우 로그 확인

respondents.each do |res| 
    Inquiry.create(:question_id=>@question.id.to_i, :respondent_id=>res.id.to_i) 
    Notifier.newgrants_notification(res).deliver 
end 

메일을 보낼 때 메일 ID가 매개 변수로 전달되므로 응답자가 res로 바뀝니다.

+0

고맙습니다. 지금은 이해합니다. 프로젝트가 프로덕션 모드 일 때만 전자 메일이 수신됩니까? –

+0

수신자 user.email도 확인하십시오 – Bijendra

+0

http://stackoverflow.com/questions/5485348/how-does-actionmailer-work/5485972#5485972 – Bijendra

1

응답자 배열을 통과 할 때 각 응답자 배열을 사용하면 파이프 (| res |)의 변수가 루프의 단일 개체를 참조하는 데 사용됩니다.

개발 모드에서
Notifier.newgrants_notification(res).deliver 
+0

고마워요! 나는이 부분을 놓쳤다! –

1

모든 이메일이 전송되지 않습니다. 그것은 모든 로그 유일의 로그 파일.이 환경에서 테스트하면 정상입니다 그래서. 당신이 그것을 :)

+0

오 그래, 내가 이것을 참조 :) 감사합니다, 그리고 로그에 내가 볼 : "[email protected]에 메일을 보냈습니다", 그래서 모두 완벽하게 일하고 있습니까? –

+0

괜찮습니다. 이제 이메일 구성을 테스트해야합니다. 그것은 작동합니다. 하지만 센드 메일이나 SMTP가 아닌지 확인하여 오류가 있는지 확인하십시오. – shingara

+0

니스. 나는 어디에서든지 smtp를 쓰지 않는다; o 그것은 나쁘니? 그렇다면 어디서 써야합니까? 이제 데이터베이스에 5 개의 전자 메일이있는 경우 로그에 5 개의 전자 메일이 수신됩니다. 좋은! –

관련 문제