Recently, I ran into a little roadblock as I’ve been cleaning up some bugs for one of my applications. I rely heavily on cross pollination of data between sites to drive traffic across my network. In this particular situation, a simple collection of linked image thumbnails accomplishes this task.
One of the helper methods that I use returns the file name of a supplied post object. To do this, I perform a regular expression match against the post’s URL and return the result.
# returns "icon/foo.jpg"
def filename_from_post(post)
return post.image.url(:icon).match(/icon\/.*\.jpg)/)[0]
end
That worked great until my application would randomly throw a NoMethodError. I spent a while scratching my head, looking over my code, checking my SQL queries, and so on and so forth. Finally, I figured it out…I had forgotten to specify a case insensitive search!
# returns nil
>> post.url(:icon).match(/icon\/.*\.jpg/)
=> nil
>> post.url(:icon).match(/icon\/.*\.jpg/i)
=> #<MatchData "icon/bar.JPG">
I guess what they say is true…the Devil is in the details.




