Complete Lesson 39 Part 1

main
Simon Quigley 1 year ago
parent da9cec4d61
commit cf7563953c

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

Loading…
Cancel
Save