Skip to content

Instantly share code, notes, and snippets.

@alexbartlow
Created June 9, 2013 21:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbartlow/5745365 to your computer and use it in GitHub Desktop.
Save alexbartlow/5745365 to your computer and use it in GitHub Desktop.
class Message < ActiveRecord::Base
scope :last_two_weeks, -> {
where(:created_at => (2.weeks.ago..Time.now))
}
scope :for_month, (date) -> {
where(:created_at => (date.beginning_of_month..date.end_of_month))
}
def self.sum_word_count
sum(:word_count)
end
end
dan.messages.for_month(2.months.ago).sum_word_count
dan.messages.last_two_weeks.sum_word_count
dan.messages.sum_word_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment