Skip to content

Instantly share code, notes, and snippets.

@jasterix
Last active June 27, 2019 21:08
Show Gist options
  • Save jasterix/fae878b10c5cdd1835e2682d61f2eb2e to your computer and use it in GitHub Desktop.
Save jasterix/fae878b10c5cdd1835e2682d61f2eb2e to your computer and use it in GitHub Desktop.
class Show < ActiveRecord::Base
def self.highest_rating
Show.maximum(:rating)
end
def self.most_popular_show
self.where("rating=?",self.highest_rating).first
end
def self.lowest_rating
Show.minimum(:rating)
end
def self.least_popular_show
self.where("rating = ?", self.lowest_rating).last
end
def self.ratings_sum
Show.sum("rating")
end
def self.popular_shows
self.where("rating > ?", 5)
end
def self.shows_by_alphabetical_order
self.order(:name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment