使用Ruby(rails)时间戳和jQuery timeago插件时遇到问题

时间:2021-02-27 22:25:52

I am passing an object back from my rails app with a timestamp. I'm trying to use jQuery to take the format it comes in and parse it to something like "5 minutes ago" "an hour ago" etc.

我正在从带有时间戳的rails应用程序传回一个对象。我正在尝试使用jQuery来获取它所带来的格式并将其解析为“5分钟前”,“一小时前”等。

$.each(data, function(i, issue){
          var created =  $.timeago(issue.created_at.to_datetime);
          ...

When I trigger the event that causes this, I get the following error:

当我触发导致此事件的事件时,我收到以下错误:

Uncaught TypeError: Object function ( selector, context ) {
    // The jQuery object is actually just the init constructor 'enhanced'
    return new jQuery.fn.init( selector, context, rootjQuery );
} has no method 'timeago'

Is there a way to do this with the timeago plugin or should I perhaps try a different method?

有没有办法用timeago插件做到这一点,或者我应该尝试不同的方法?

1 个解决方案

#1


0  

Why not use a rails built-in method?

为什么不使用rails内置方法?

<%= time_ago_in_words(issue.created_at) %>

#1


0  

Why not use a rails built-in method?

为什么不使用rails内置方法?

<%= time_ago_in_words(issue.created_at) %>