Rails 中的复数视图问题

发布于 2024-12-27 01:45:28 字数 213 浏览 3 评论 0原文

我有一个关于复数函数的问题。在我看来,我有以下代码行。它传递具有一定票数的项目,以确定“Vote”一词是否应该采用复数形式。

 <%= pluralize(item.votes, 'Vote') %>

我的问题是我的观点传递了“投票”一词,后跟一定数量的投票(item.votes)。我只想让它传递“投票”这个词。非常感谢您的想法。

I have a question about the pluralize function. In my view, I have the following line of code. It passes in an item with a certain number of votes to determine if it the word "Vote" should be pluralized.

 <%= pluralize(item.votes, 'Vote') %>

My issue is that my view passes out the word "Votes" followed by the certain number of votes (item.votes). I only want it to pass out the word "Votes". Ideas are much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鲸落 2025-01-03 01:45:28

你可以做的更简单:

"Vote".pluralize(item.votes)

You can do simpler:

"Vote".pluralize(item.votes)
青春如此纠结 2025-01-03 01:45:28

您可以这样做:

pluralize(items.votes, 'Vote').split(" ", 2)[1]

希望有帮助!

You can do:

pluralize(items.votes, 'Vote').split(" ", 2)[1]

Hope that helps!

旧伤还要旧人安 2025-01-03 01:45:28

您可以在助手中创建自己的方法

def pluralize_without_count(string, count)
    count == 1 ? string : string.pluralize
end

并在您的视图中使用它:

<%= pluralize_without_count('Vote', item.votes) %>

You can create your own method in a helper

def pluralize_without_count(string, count)
    count == 1 ? string : string.pluralize
end

and use it in your view:

<%= pluralize_without_count('Vote', item.votes) %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文