require 'config/environment'
inquiry = Inquiry.find(:all, :conditions => ["is_answered = 0"])
inquiry.each do |i|
question = i.question
user = User.find(:first, :conditions => ["id = ?", question.user_id])
Notifier.deliver_deadline_notification(inquiry, user, question)
end
테이블 inquiry
(관계 테이블)에 is_answered
필드 (예 :)가 있습니다.조치 도움말 MAIL
내가 필요한 것? 내 질문에 NOT answered
인 이메일을 보내야합니다 (is_answered = 0
). (난 데이터베이스에 나와 있지 않은 1 개 질문 2 사용자가 있기 때문에) 내가 2
이메일을받은 : 그래서 지금이 방식으로 작동
id | question_id | is_answered
14 | 11 | 0
24 | 11 | 0
그래서, 난 ONLY ONE EMAIL
하지 두를받을 필요! 전자 우편에서 나는 질문에 관하여 몇몇 통계를 쓰고 싶다. 그러나 나는 단 하나의 이메일이 필요하다! 어떻게 할 수 있습니까?
감사합니다.
------------------ UPD -----------------
model/notifier.rb
def deadline_notification(inquiry, user, question, respondent)
recipients user.email
from "[email protected]"
subject "Finished"
content_type "text/html"
body(:question => question.text, :respondent => respondent.email)
end
model/inquiry
class Inquiry < ActiveRecord::Base
belongs_to :question
belongs_to :respondent
has_one :answer, :dependent => :destroy
model/question
class Question < ActiveRecord::Base
has_many :inquiries, :dependent => :destroy
has_many :answers, :through => :inquiries, :dependent => :destroy
belongs_to :user
end
model/respondent
class Respondent < ActiveRecord::Base
has_many :inquiries, :dependent => :destroy
has_many :questions, :through => :inquiries
belongs_to :user
end
model/user
class User < ActiveRecord::Base
has_many :questions
has_many :respondents
TODO : 발견 70 명의 응답자 (정확히 누가 누구인가)와 그렇지 않은 사람 모두가 is_answered = 0 인 경우 (예 : 100 명의 응답자와 70 명의 응답자가 있음) ME 이메일 (사용자가 질문을 추가 했음) 대답했다. 이메일 하나만 보내주세요!
PS - 이제 나는 30 이메일 (나와 있지 않은 사람) 받았지만, 내가 잘못 생각 : D
그것은 질문에 대한 답변하지 않은 모든 사용자를 찾을 수 있습니다 당신이 여기서 뭘하려고 같은 소리
도와 주셔서 감사합니다. 내 게시물을 업데이트했습니다. 고맙습니다! –