Tag Archives: Rails
Rails Gotcha: ActiveRecord Caches Associated Records by Default
ActiveRecord will cache the results of association method calls by default, unless you tell it not to. (This applies to Rails 2.3.2 and perhaps earlier versions.) From the documentation: project.milestones # fetches milestones from the database project.milestones.size # uses the … Continue reading
Quick Hits: Setting the User Agent Header in Webrat
If you’ve read the new PragProg beta e-book on RSpec, you may have read that you can set HTTP headers for your Webrat request like so: Given /^I am browsing the site using Safari$/ do header "User-Agent" , "Mozilla/5.0 (Macintosh; … Continue reading
Better Rails Searching with Named Scopes using Scope Builder
When it comes writing elegant search code in a Rails app, Named Scopes immediately come to mind. And for good reason: they’re a fantastic way to express, well, scopes, for your searches. In your Person model, you might have named … Continue reading