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.
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...
You can create your own
case created_at.hour
when (4..10)
"Breakfast"
when (10..14)
"Lunch"
when (14..22)
"Supper"
else
"Night"
end
You can also wrap it as a method or extend DateTime
class with it
精彩评论