A Bad Idea

I just ran afoul of an old bad idea I had. My comic book site, My Pull List, allows you to browse upcoming releases by date. To keep the URLs intuitable, I had this in my routes.rb:

...
i.with_options :action => 'index', :year => Date.today.year, :month => Date.today.month do |rel|
...
rel.releases 'releases/:year/:month/:day', :day => nil
end
...

Unfortunately, routes.rb is only read when the application server is started, which means that those Date.today.year and Date.today.month default parameters always refer to the date I last restarted mongrel. And since my application doesn’t need restarting quite as often as, say, DHH’s apparently do, this means that there was a case in which you could click a link expecting to see comics being released on January 16th, 2008, and instead see releases for December 17th, 2007.

Let that be a lesson to all of us: keep in mind the context in which your code will be evaluated.

(Incidentally, if you’re interested in using this knowledge for good instead of evil, check out the CachesConstants plugin)

Leave a Reply