Skip to content
No description or website provided.
Ruby JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
store
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.