简体   繁体   English

在Rails观点中处理英语多元性的最佳方法是什么?

[英]What's the best way to deal with English pluralisation in a rails view?

I generally do something like this, but if feels nasty and not very dry: 我通常会做这样的事情,但是如果感到讨厌并且不太干燥:

-if minutes == 1
  added #{minutes} minute ago
-else
  added #{minutes} minutes ago
<%= pluralize(minutes, "minute") %> if you're in a view.

See http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-pluralize 参见http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-pluralize

"added #{ pluralize(minutes, "minute") } ago"

There is an optional third argument that you can add if the plural version is non-standard and rails can't figure it out. 如果复数版本为非标准版本且rails无法弄清楚,则可以添加第三个可选参数。 For example (from the docs): 例如(来自文档):

pluralize(3, 'person', 'users')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Rails 3中处理虚荣URL帮助的最佳方法是什么? - What is the best way to deal with Vanity URL helpers in Rails 3? 使用 rails 的 attr_accessible/security 问题 - 处理这个问题的最佳方法是什么? - attr_accessible/security question with rails - what is the best way to deal with this? 在rails中,处理真实大文件(例如视频)的最佳方法是什么,你不想提交给repo和资产管道? - In rails, what's the best way to deal with really large files (e.g. videos) that you do not want to commit to the repo and asset pipeline? 在Rails中处理与时区无关的时间的好方法是什么 - What's a good way to deal with timezone-independent time in Rails Rails:什么是处理空params数组的好方法 - Rails: What's a good way to deal with empty params array 在Rails中处理不存在的变量的最佳方法是什么? - What's the optimal way to deal with non-existent variables in Rails? 什么是处理大量控制器的“Rails方式”? - What's the “Rails way” to deal with a large number of controllers? 在 Rails 4 中实现角色的最佳方式是什么? - What's the best way to implement roles in Rails 4? Rails 4处理过滤器的方式是什么? - What is the Rails 4 way to deal with filters? 在Rails中按日期搜索的最佳方法是什么? - What's the best way to search by date in Rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM