开发者

Rails helper, show word not date

开发者 https://www.devze.com 2023-01-03 12:48 出处:网络
A follow on from this questions: http://stackoverflow.com/questions/3032598/rails-created-at-on-display-if-today

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) %>
0

精彩评论

暂无评论...
验证码 换一张
取 消