Hi! I'm Avdi Grimm, and this is my software development blog. More...
Books and Screencasts
Small plates of gourmet Ruby code.
Watch me build an app from scratch.
Objects on Rails
A developer notebook on applying classic Object-Oriented principles to Ruby on Rails projects.
The definitive guide to exceptions and failure handling in Ruby.
Tag Archives: activerecord
NullDB, for those who don’t know, is a null backend for ActiveRecord. Unlike RSpec’s stub_object, rather than raise an exception on DB access, will NullDB DB interactions simply become no-ops. This is handy for things like testing after_save hooks in … Continue reading
How to add helper methods to all associations of a given type, as well as to the model class. Continue reading
Avoiding silent truncation of your model fields requires putting length validations on them. But this can introduce duplication of knowledge. In this post I demonstrate how to pull limit information directly from the DB into your model validations. Continue reading
Projects using Ruby on Rails often lack strong distinctions in two main areas: The model/record conflation: Seeing “models” as strictly DB-backed resources. The view/template conflation: failing to draw a line between view objects and HTML templates. The conflations are encouraged … Continue reading
So I was messing around with some scratchpad code today, investigating the use of with_exclusive_scope, and here’s what I had to write to come up with a minimal working ActiveRecord model: require ‘rubygems’ require ‘active_record’ ActiveRecord::Base.establish_connection( :adapter => “sqlite3″, :database … Continue reading
I love Open Source. NullDB, a weekend hack that I barely touched after its first version, continues to attract periodic forks and patches. For a long time I’ve been meaning to sit down and roll in all the contributions that … Continue reading
François Beausoleil has a nice post up demonstrating “how to use AlterEgo with ActiveRecord”:http://blog.teksol.info/2008/12/09/how-to-use-alterego-with-activerecord.html. If you’re interested in introducing state-specific behaviors to your ActiveRecord objects, check it out!