Created
September 26, 2010 09:06
-
-
Save lachlanhardy/597754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Redundant in the sense of repetition :-)
Anyway, looks like things are working fine for you