Rails 定制的“time_ago_in_words”类型模型
大家早上好!
我正在开发一个 Rails 应用程序,只需简单检查是或否,然后它会显示 created_at
行以及选中的框。我的问题是我需要将 created_at
显示为不同的值,而不是时间。如果有人在凌晨 4:00 至上午 10:00 之间创建了一个条目,则会在 created_at
字段的视图中显示早餐。如果他们在上午 10:00 到下午 2:00 之间创建它,它将显示午餐。
我在 Google 上搜索了几个小时,我能想到的最接近的东西是 time_ago_in_words
的一些变体,但没有任何效果。
我将如何实施这种性质的事情?
全面披露:我对 Ruby/RoR 有点业余。温柔一点...
Morning, everyone!
I'm working on a Rails app that is just a simple check yes or no, then it displays the created_at
row and whichever box was checked. My issue is that I need to display the created_at
as a different value, not the time. If someone created an entry between 4:00 AM - 10:00 AM, it would display Breakfast in the view for the created_at
field. If they created it between 10:00 AM and 2:00 PM, it would display Lunch.
I've Googled for hours, and the closest thing I could come up with is some variation of time_ago_in_words
but nothing really works.
How would I go about implementing something of this nature?
Full disclosure: I'm a bit of an amateur at Ruby/RoR. Be gentle...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建自己的
您也可以将其包装为方法或用它扩展
DateTime
类You can create your own
You can also wrap it as a method or extend
DateTime
class with it