Complete Lesson 39 Part 1

main
Simon Quigley 1 year ago
parent da9cec4d61
commit cf7563953c

@ -18,9 +18,11 @@ class Movie < ApplicationRecord
def flop?
total_gross.blank? || total_gross < 225_000_000
end
def self.released
where("released_on < ?", Time.now).order(released_on: :desc)
end
scope :released, -> { where("released_on < ?", Time.now).order("released_on desc") }
scope :upcoming, -> { where("released_on > ?", Time.now).order("released_on asc") }
scope :recent, ->(max=5) { released.limit(max) }
def average_stars
reviews.average(:stars) || 0.0
end

Loading…
Cancel
Save