我正在构建一个博客应用程序.如果"发布"了多个"帖子",我希望能够将"文章"一词复数
就像这样:
这就是我的....
Available <%= pluralize @posts.published, "Article" %>:
我试过了
Available <%= pluralize @posts.published.count, "Article" %>:
这很有效...但我不想要号码.它不应该阅读可用的5篇文章....它应该没有号码.
我正在构建一个博客应用程序.如果"发布"了多个"帖子",我希望能够将"文章"一词复数
就像这样:
这就是我的....
Available <%= pluralize @posts.published, "Article" %>:
我试过了
Available <%= pluralize @posts.published.count, "Article" %>:
这很有效...但我不想要号码.它不应该阅读可用的5篇文章....它应该没有号码.
我一直在寻找这个问题的答案,但对现有的任何一个都不满意.以下是我找到的最整洁的解决方案:
Available <%= "Article".pluralize(@posts.published.count) %>:
文件是here.相关位:
返回字符串中单词的复数形式.
If the optional parameter count is specified, the singular form will be returned if count == 1. For any other value of count the plural will be returned. 'post'.pluralize # => "posts" 'apple'.pluralize(1) # => "apple" 'apple'.pluralize(2) # => "apples"