Skip to content

Instantly share code, notes, and snippets.

@lachlanhardy
Created September 26, 2010 09:06
Show Gist options
  • Save lachlanhardy/597754 to your computer and use it in GitHub Desktop.
Save lachlanhardy/597754 to your computer and use it in GitHub Desktop.
# to explain
# ActionView lets me write
# pluralize(something.length, "Thing") =>
# "2 Things"
#
# But in this case, I want to separate the number from the text in HTML (to put an icon in between).
# Since I'm using CSS sprites, the easiest way is to wrap the text in a span with a class on it to get the correct image
# Thus:
def new_pluralize (number, text)
class_name = text.downcase
unless number == 1
text = text.pluralize
end
"#{number} <span class=\"#{class_name}\">#{text}</span>"
end
# Which lets me call
# new_pluralize(something.length, "Thing") =>
# "2 <span class="thing">Things</span>"
# Then all I have to do is insert it in my view without escaping the HTML
@stephan-buckmaster
Copy link

Redundant in the sense of repetition :-)

Anyway, looks like things are working fine for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment