views:

24

answers:

1

Hi Everyone,

Currently I have the following in my helper:

def created_today k 
  if k.created_at.to_date == Date.today then 
    content_tag(:span, 'Today', :class => "todayhighlight") 
  else 
    k.created_at.to_s(:kasecreated) 
  end
end

What I would like to do is replace TODAY with MOMENTS AGO if the created_at time is within the last 10 minutes.

Is this possible?

Would I just add another 'if' line after the current 'if k.created_at.to_date == Date.today then'?

Thanks,

Danny

UPDATE:

def created_today k 
  if k.created_at.to_date == Date.today then 
    content_tag(:span, 'Today', :class => "todayhighlight") 

  if k.created_at > 1.minutes.ago then
    content_tag(:span, 'Moments Ago', :class => "todayhighlight") 

  else 
    k.created_at.to_s(:kasecreated) 
  end
end
+1  A: 

You could do

 if k.created_at > 10.minutes.ago then
   ...
 elsif k.created_at.to_date == Date.today then
   ...
 else
   ...

Note that you have to put the 10-minute-check before the today-check because a date less than 10 minutes ago is most likely on the same day.

Sven Koschnicke
Hi Sven, that works in place of the current if statement. How do I combine multiple? See updated question.
dannymcc
Updated my answer. Is it clear now?
Sven Koschnicke
Worked a charm, thank you!
dannymcc