Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 store
Octocat-spinner-32 README
README
Railscasts Episode #152: Rails 2.3 Extras

http://railscasts.com/episodes/152

Commands

  gem install rails --source http://gems.rubyonrails.org


Console

  # find in batches
  Product.count
  Product.find_in_batches(:batch_size => 10) do |batch|
    puts "Products in batch: #{batch.size}"
  end
  Product.each(:batch_size => 10) do |product|
    puts product.name
  end
  
  # scoped_by
  Product.scoped_by_price(4.99).size
  Product.scoped_by_price(4.99).first
  Product.scoped_by_price(4.99).scoped_by_category_id(3).first

  # try method
  Product.find_by_price(4.99).name
  Product.find_by_price(4.95).name
  Product.find_by_price(4.95).try(:name)
  Product.find_by_price(4.99).try(:name)
Something went wrong with that request. Please try again.