saasbook

Untitled

Oct 1st, 2012
968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.36 KB | None | 0 0
  1. class Movie < ActiveRecord::Base
  2.   has_many :reviews
  3.   def inspect ; "#{title} (#{rating}) - #{release_date.strftime('%D')}" ; end
  4.   scope :for_kids, :conditions => ['rating IN (:ratings)', :ratings => %w(G PG)]
  5.   scope :with_good_reviews, lambda { |cutoff|
  6.     joins(:reviews).
  7.       group(:movie_id).
  8.       having("AVG(reviews.potatoes) > #{cutoff}")
  9.   }
  10. end
Advertisement
Add Comment
Please, Sign In to add comment