My blog (i.e., this blog) suddenly stopped working today, so I went to the logs to figure out why. The logs provided:
ActionView::TemplateError (undefined method `first' for nil:NilClass) on line #9 of vendor/plugins/flickr_sidebar/views/content.rhtml: [... lots and lots of stuff ...]
Ah, OK. I haven't gotten Typo current since I decided to roll my own (which I'm still doing...), so it serves me right if some bug is biting me. Off to look at the Flickr sidebar, and this chestnut is what's choking things:
def image
description.scan( /(http:\/\/(static|photos).*?\.jpg)/ ).first.first
end
Gah! Using a regular expression to capture a link to an image out of escaped HTML markup passed in the RSS feed... Not something I would recommend. Flickr changed their URLs so that the regular expression no longer matched, and the error was caused by scan returning nil. It's easy enough to fix by adding some namespaces:
@@NS = {"media" => "http://search.yahoo.com/mrss/" }
And then, a couple of tweaks to extract the thumbnail from the appropriate extension element:
picture.thumbnail = XPath.match(elem, "media:thumbnail/@url", namespaces=@@NS).to_s
And we're back in business.












Comment from Frank @ 2006-12-21T04:14:48Z # permalink
Comment from Paul Brown @ 2006-12-21T14:31:16Z # permalink