Ruby on rails 铁路";“刚才”;而不是创建日期?

Ruby on rails 铁路";“刚才”;而不是创建日期?,ruby-on-rails,datetime,date,Ruby On Rails,Datetime,Date,目前我的助手中有以下内容: 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 如果在时间创建的在最后10分钟内,我想用几分钟前的时间替换今天 这可能吗 我会在当前的“if k.

目前我的助手中有以下内容:

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
如果在时间创建的
在最后10分钟内,我想用几分钟前的时间替换今天

这可能吗

我会在当前的“if k.created_at.to_date==date.today then”之后再添加一行“if”吗

谢谢

丹尼

更新:

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
你可以

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

请注意,您必须将10分钟检查放在今天检查之前,因为不到10分钟前的日期最有可能在同一天。

Hi Sven,这可以替代当前的if语句。如何合并多个?见更新的问题。