Advertisement
saasbook

scopes_antipattern.rb

Aug 15th, 2013
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.32 KB | None | 0 0
  1. # BAD: details of computing review goodness is exposed to controller
  2. class MoviesController < ApplicationController
  3.   def movies_with_good_reviews
  4.     @movies = Movie.joins(:reviews).group(:movie_id).
  5.       having('AVG(reviews.potatoes) > 3')
  6.   end
  7.   def movies_for_kids
  8.     @movies = Movie.where('rating in ?', %w(G PG))
  9.   end
  10. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement