题
我有一个例子,我需要使用复数来正确拼写某些内容。但是,我需要像这样渲染 html:
<span>1</span> thing
或者,
<span>3</span> things
我可以编写一个辅助方法,但我只是确保框中没有任何东西可以执行此操作。
解决方案 2
在此期间,我创建这个辅助方法,因为它看起来像没有我要找的:
def pluralize_word(count, singular, plural = nil)
((count == 1 || count == '1') ? singular : (plural || singular.pluralize))
end
这是对以复数方法基本相同,不同之处在于它消除从前面的数量。这使我要做到这一点(HAML):
%span.label= things.size.to_s
%description= pluralize_word(things.size, 'thing')
不隶属于 StackOverflow