public
Last active — forked from rails/gist:264500

Rails 3

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8
products = Product.where("price = 100").limit(5) # No query executed yet
products = products.order("created_at DESC") # Adding to the query, still no execution
products.each { |product| puts product.price } # That's when the SQL query is actually fired
 
class Product < ActiveRecord::Base
named_scope :pricey, where("price > 100")
named_scope :latest, order("created_at DESC").limit(10)
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.