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
字段(例如)。幫助與行動郵件
我需要什麼?我需要在我的問題(is_answered = 0
)上發送電子郵件爲NOT answered
的人。所以,現在的工作是這樣的:我收到的電子郵件2
(因爲我在數據庫中有1個問題和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:找到(例如,我有100個受訪者,並且有70個人被回答)並且發送了ME電子郵件(用戶,他補充了問題確定,(它正在工作)),70個回答者回答了(並且完全正確)和誰不回答回答。只需發送一封電子郵件!
PS - 現在,我收到30個電子郵件(誰不回答),但我認爲這是錯誤的:d
謝謝你試圖幫助我。我更新了我的帖子。謝謝! –