Now I’m trying to make helper method like this.
How can I compare the datetime of argument with Today’s date?
def todate_datetime(date_time)
date_time = Date.today ? "<font color='red'>#{date_time}</font>" : date_time
end
UPDATE:
view
<%= today_datetime(community_topic.updated_at) %>
helpers
def today_datetime(date_time)
date_time == Date.today ? "<font color='red'>#{date_time.to_s(:ct)}</font>" : date_time.to_s(:ct)
end
Starting from ruby 1.9.2 you can directly compare a DateTime object with a Date object in ruby, e.g. try in irb:
However, Rails has its own DateTime object (APIdock Rails DateTime). One option is to convert the Rails Object to a date via the
to_datemethodSo then the helper method could look like this:
EDIT: it might be more accurate to compare the
date_timeargument toDateTime.current.to_datesince that takes theconfig.time_zoneinto account if set: