Skip to content

Instantly share code, notes, and snippets.

@superbilk
Last active December 14, 2015 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superbilk/5137493 to your computer and use it in GitHub Desktop.
Save superbilk/5137493 to your computer and use it in GitHub Desktop.
How do I refactor this? DEPRECATION WARNING: Relation#calculate with finder options is deprecated. Please build a scope and then call calculate on it instead. (called from averages at /app/models/star.rb:7) Code is simplified.
class Star < ActiveRecord::Base
default_scope order: 'registered_at DESC'
scope :registered_before, ->(days) { where("registered_at >= ?", days.days.ago) }
def self.averages days = 90
registered_before(days).average(:stars, group: "DATE(registered_at, '+1 day')")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment