Avoid rails helper times_ago_in_words()

Let’s say we have 100 records in lessons table then
 %td.last_modified= times_ago_in_words(lesson.updated_at)

server calculate the time ago for each record for each request, it wastes a lot of time on server side.
If we replace above code by

 %td.last_modified"= lesson.updated_at.to_s

and load jquery plugin 

<script src="jquery.timeago.js" type="text/javascript"></script>

then in JavaScript

$(“td.last_modified”).timeago()

thats it.
Then the javascript will calculate the time ago on client side after loading the page in browser.
So you can enhance your app response time. 

For more info about timeago jquery plugin click here

Thanks

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s