making it more convenient to be plural
May 23, 2008 by Eric Richardson
Hello again neglected blog...
Ever since the April 1st launch of the new blogdowntown code, there's been a sloppy little bug that's bothered me, but not quite been bad enough to address. When putting comment counts on stories, I got sloppy and wrote:
<%= thumbnail.comments.length %> Comments
instead of being proper and making sure account for the singular case. Bottom-line: the conditional is ugly. I didn't want to have to write this everywhere:
<%=
story.comments.length.to_s + " " +
(story.comments.length == 1) ? "Comment" : "Comments"
%>
So tonight I finally made the fix, but did it in a way that doesn't assault my senses.