2013-06-27 3 views
0

는 지금은 함수 time_sinceRails에서 업데이트 된 시간을 표시하는 방법은 무엇입니까?

def time_since 
    seconds = Time.now - self.updated_at 
    if seconds < 15 
     display = "Just Now" 
    elsif seconds < 59.5 #less than 59.5 seconds 
     display = seconds.round(0).to_s + "s" 
    elsif seconds < (3600-30) #less than 59.5 minutes 
     display = (seconds/60).round(0).to_s + "m" 
    elsif seconds < (86400-1800)  #less than 23.5 hours 
     display = (seconds/3600).round(0).to_s + "h" 
    elsif seconds < 86400*2 #less than 2 days 
     display = "Yesterday" 
    elsif seconds < 86400*7 #less than 1 week 
     display = self.updated_at.strftime("%A") 
    else      #more than 1 week 
     mon = self.updated_at.month 
     day = self.updated_at.day.to_s 
     display = day + convert_month_number_to_month_name(mon).to_s 
    end 

    return display 
end 

이 그리고이 위에 마우스를 할 수 있도록하려면하고 정확한 updated_at 타임 스탬프를 표시합니다. 이 작업을 쉽게 수행 할 수있는 보석이 있습니까?

+1

http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words –

+0

@anonymousxxx 기본적으로 당신이 좋아하는 무언가를 링크했습니다. 거기에 구현했습니다. 그러나 더 많은 것은, 당신의 질문이다 1 개의 원본을 표시하는 방법, 그러나 그 후에 hover 원본을 추가하십시오? 멋진 도구를 제공하는 보석/라이브러리가 있지만, 기본 자바 스크립트를 검색하여 호버링 이벤트를 가져 오거나 웹 브라우저에서 호버에 표시되는 '제목'을 사용할 수도 있습니다. – MrDanA

+0

이것은 모두 끝내 주지만, 이제는 오류가 발생합니다 : 정의되지 않은 메소드'distance_of_time_in_words '. 해당 메소드에 액세스하기 위해 새로운 무언가를 포함해야합니까? – GoodLuckGanesh

답변

0

나는이를 사용하여 종료 :

<span title=<%= Object.updated_at.localtime.asctime.split.join('-') %>> 
    <%= distance_of_time_in_words_to_now(Object.updated_at, include_seconds = true) %> 
</span> 

나는 제목이 시간의 첫 번째 단어 이상을 보여 가져올 수 없습니다 그래서 대시 (나는의 strftime을 사용하는 경우에도)로 합류했다. 이것은 기능적이며 나중에 정리할 것입니다.

관련 문제