简体   繁体   中英

Having trouble with Ruby(rails) timestamp and jQuery timeago plugin

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.

$.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?

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

<%= time_ago_in_words(issue.created_at) %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM