Oh no you didn't...?!

Paul Brown @ 2006-12-21T00:19:56Z

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.

Meta

Tags: (tag) (tag) (tag) (tag) (tag)

(comment bubbles) 2 comments
2405 direct views

Comment from Frank @ 2006-12-21T04:14:48Z # permalink

could you please explain where you applied those fixes? I can't seem to get it working

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

Here's the updated flickr.rb. Put it in vendor/plugins/flickr_sidebar/flickr/lib. I left out a few details about changing the name of the accessor and the replacement regex.