Archive for December, 2007

CacheSweepers and url_for

Monday, December 31st, 2007 Posted in ActionController, ActionView, Rails, Ruby | No Comments »

It appears url_for only seems to work correctly in a CacheSweeper when running a server in production mode. I've confirmed this in Rails 2.0.2. class MySeeper < ActionController::Caching::Sweeper observe Item def after_create(item) value = url_for(:controller => :items) end end In development mode, value evaluates ...

Autotest with growl

Monday, December 17th, 2007 Posted in Uncategorized | No Comments »

Here is my .autotest file. It's based on John Nunemaker's guide: module Autotest::Growl IMAGE_ROOT = "~/.autotest_images" def self.growld title, msg, img, pri=0, sticky="" system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}" ...

Enumerable#sort

Wednesday, December 12th, 2007 Posted in ActiveRecord, Rails, Ruby | No Comments »

In Ruby, to sort a collection of Objects, the <=> method needs to be defined. Suppose we have the following: # has a field created_at, which is a datetime class Event < ActiveRecord::Base end Let's say we want to do the following: @events = Event.find(:all) @events.sort To ...