A follow on from this questions:
http://stackoverflow.com/questions/3032598/rails-created-at-on-display-if-today
Is it possible to output the word TODAY rather than the date when using the following helper?
def created_today k
k.created_at if k.created_at.to_date == Date.t开发者_Go百科oday
end
<%=h created_today(k) %>
Thanks,
Danny
def created_today k
"Today" if k.created_at.to_date == Date.today
end
If you want to display the date if it's not today:
def created_today k
if k.created_at.to_date == Date.today then
content_tag(:span, 'Today', :class => "highlight")
else
k.created_at.to_s(:long)
end
end
In your css, you describe how you want to 'highlight' it
def created_today k
'TODAY' if k.created_at.to_date == Date.today
end
<%=h created_today(k) %>
精彩评论