I want to send mail which will have day to day report. I have setup action mailer like thisclass ReportMailer < ApplicationMailer  ...  def send_stats(hash)    @emails = [my@email.com]    @stat = hash    mail(:to => @emails.join(,), :subject => Daily Count of tasks)    endendThe send_stats method will need parameter hash which should be passed. This hash will have different counts which are not limited to one model. So I came with an idea of report module.module Report  def self.email_stats(date)    hash = {}    hash[TaskCount] = Task.where(adate: date).count    hash[ProfileCount] = Profile.where(ad_date: date).count    ReportMailer.delay.send_stats(hash)  endendIs this a right approach? Does anyone have better idea than this?
Where should I put code which calculates stats which will be sent via mail
ruby;ruby on rails
So far as I can tell without seeing the rest of your of your application structure this seems fine. I am making the assumption that this is small app and that performance is not a real concern as of yet. One suggestion though, you could take those where statements and internalize them in their respective models as scopes. scope :task_count, -> (date) { where(:adate => date).count }scope :profile_count, -> (date) { where(:ad_date => date).count }This would at least neaten things up a bit and is a good habit to form, because it will insure consistency in behavior. Even though these are simple queries if you are reimplementing them (or any query) everywhere it creates the possibility to introduce errors; this is a benefit of code reuse.