Skip to main content

Vincent Tsao's Library tagged rails   View Popular

17 Sep 09

Active Record Query Interface

  • Behind the scenes find_each fetches rows in batches of 1000 and yields them one by one. The size of the underlying batches is configurable via the :batch_size option.


    To fetch User records in batch size of 5000:

  • User.find_each(:batch_size => 5000) do |user|
    NewsLetter.weekly_deliver(user)
    end
  • 1 more annotations...

Active Record Validations and Callbacks

  • 17 Observers


    Observers are similar to callbacks, but with important differences. Whereas callbacks can pollute a model with code that isn’t directly related to its purpose, observers allow you to add the same functionality outside of a model. For example, it could be argued that a User model should not include code to send registration confirmation emails. Whenever you use callbacks with code that isn’t directly related to your model, you may want to consider creating an observer instead.

26 Mar 09

Softies on Rails: Ruby 201: Weird Hash Syntax

  • vehicles = { :cars => 36, :boats => 8, :trains => 12, :planes => 21 }

    vehicles.select { |k,v| v > 20 }
    => [[ :planes, 21], [ :cars, 36]]
  • a = [[:planes, 21], [:cars, 36]].flatten
    => [ :planes, 21, :cars, 36]
  • 5 more annotations...
1 - 20 of 135 Next › Last »
Showing 20 items per page

Highlighter, Sticky notes, Tagging, Groups and Network: integrated suite dramatically boosting research productivity. Learn more »

Join Diigo