Forum: Ruby on Rails Send mail only when a condition satisfy

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dat C. (Guest)
on 2008-11-10 20:50
(Received via mailing list)
I would like to send a digest of what have been changed in a day to
some admins. However, some day there won't be any change. How do I not
send emails on such cases?

Currently, my mailer is called Postoffice. I call
Postoffice.deliver_daily_digest every night by a cron job.

Inside of daily_digest method, I have queries to figure out what have
been changed. I don't want to repeat these queries in my rake task.
Any suggestions would be appreciated.
Frederick C. (Guest)
on 2008-11-10 22:33
(Received via mailing list)
On 10 Nov 2008, at 16:32, Dat C. wrote:

> Any suggestions would be appreciated.
>
I would extract those queries from the mailer into some other class
(eg DailyReporter).
The mailer is then just something dumb which inserts data passed to it
in various parts of the template

Usage might look like

report = DailyReporter.run
if report.anything_happened?
   Postoffice.deliver_daily_digest(report)
end

Fred
This topic is locked and can not be replied to.