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…

Reload or Add routes at runtime in Rails 3

In one of my project, we needed SEO friendly Menu urls like /brandy/cognac. For this, we added a generic route/:parent/:child/:grandchild at the bottom of routes.rb. With this approach, there was an issue with invalid urls like /this/is/wrong being redirected to specified controller action. To fix this, we used Menu names to generate specific urls. But the routes would become invalid if Admin…

jquery ketchup-plugin for Client-side form-validation:

jquery ketchup-plugin for Client-side form-validation: There are many jquery plugins available for client-side form validation (to validate form before actually submitting it). jquery ketchup-plugin is one of them. Github: https://github.com/mustardamus/ketchup-plugin Demo: http://demos.usejquery.com/ketchup-plugin/ Validations provided by plugin: https://github.com/mustardamus/ketchup-plugin/blob/master/jquery.ketchup.validations.js Steps: 1. include css file in your application.css file *= require jquery.ketchup 2. include js file in your…