Where should I put code which calculates stats which will be sent via mail I want to send mail which will have day to day report. I have setup action mailer like this

class ReportMailer &lt; ApplicationMailer
  ...

  def send_stats(hash)
    @emails = ["my@email.com"]
    @stat = hash
    mail(:to =&gt; @emails.join(","), :subject =&gt; "Daily Count of tasks")  
  end
end


The 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)
  end
end


Is this a right approach? Does anyone have better idea than this?
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, -&gt; (date) { where(:adate =&gt; date).count }
scope :profile_count, -&gt; (date) { where(:ad_date =&gt; 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.