From cf7563953cdc08ccdac4ab062cadc47028718671 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Wed, 27 Sep 2023 08:25:17 -0500 Subject: [PATCH] Complete Lesson 39 Part 1 --- app/models/movie.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/movie.rb b/app/models/movie.rb index d8a80ec..98b258d 100644 --- a/app/models/movie.rb +++ b/app/models/movie.rb @@ -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