Rails|Ransack|Geocoder – Sort data by distance

If your application connects local businesses to local customer, then you might have used Ransack for sorting and searching of records. For geocoding and reverse-geocoding, you might be using Geocoder gem. If you want to let users to sort results by distance then its pretty easy.

Things to remember,

  • If you use Model.near([lat, long]) method, Ransack adds a new column called distance to the ActiverecordRelation object. You can access the method distance by prying.

Continue reading

jQuery DataTables: Turn-Off / Customize the default sorting / initial sorting for jquery DataTables

By default jQuery DataTables plugin sorts the table alphabetically in ascending order using the first column. However, if this irritates you or does not fit your requirement then you can turn it off. Continue reading