Archive for October, 2014

Common mistakes in RoR

Posted: October 24, 2014 in Uncategorized

Few common mistakes, must be taken care of while developing RoR applications.

via Common mistakes in RoR.

Here we will discuss about the server side datatable with rails 4.
I was working with a project where we need to list/show a few thousands of records in a table, pagination, sortingĀ  and also advanced searching for those records. So for this scenario I had to use a datatable (server side).

So today we will see how the datatable can be used with serverside in rails 4.

jQuery Datatable can be used for sorting, searching, paginating a number of records in a table.


First of all we need include the js and css in the application.js and the application.css respectively.

require dataTables/jquery.dataTables

Now first we will write the code for view then controller then datatables.
In the view, lets see a piece of code as the example.
Suppose we have to show User name, email, joining date etc.

<table id="users_listing" class="datatable-list">
    <th>User Name</th>
    <th>Join Date</th>

Now we have to make a datatable folder for the model so that we can save all the datatable at the same place , it may useful when we have more than one datatable. Like assets , controller, model folder we will make datatable folder, in that we will make user_datatable.rb

class UsersDatatable
delegate :params, :h, :link_to, :edit_user_path, to: :@view

def initialize(view)
@view = view

def as_json(options = {})
sEcho: params[:sEcho].to_i,
iTotalRecords: User.all.count,
iTotalDisplayRecords: users.total_count,
aaData: data

in the private methods we have to write the methods for data


def data do |user|
link_to(, edit_user_path(user)),,
(user.status ? 'Active': 'Inactive'),
link_to('Delete', admin_user_path(user, type: 'users'), method: :delete, data: {confirm: 'Are you sure to delete this user?'})

def users
@users ||= fetch_users

def fetch_users

if user_search.present?
#do something


def page
params[:iDisplayStart].to_i/per_page + 1

def per_page
params[:iDisplayLength].to_i &amp;gt; 0 ? params[:iDisplayLength].to_i : 10

def sort_column
columns = %w[first_name email created_at sum(test_23.total_ad) total status]

def sort_direction
params[:sSortDir_0] == &quot;desc&quot; ? &quot;desc&quot; : &quot;asc&quot;

def user_search
#here you can write searching mechanism.


Now moving to controller

render json:

in the js file we need to add this

  var table = $("#users_listing").DataTable({
        iDisplayLength: 100,
        bInfo: false,
        bSort: true,
        sPaginationType: "full_numbers",
        bStateSave: true,
        bDestroy: true,
        bProcessing: true,
        bServerSide: true,
        bFilter: false,
        sAjaxSource: '/test_users/search',
        fnServerParams: function (aoData) {
                { "name": "email_or_name", "value": $("#_email_or_name").val() },
                { "name": "check_token", "value": check_token_value },
                { "name": "from_no_of_tokens", "value": from_token_value }
                { "name": "status", "value": $("#_status").val() }
        "aoColumns": [ null,  null,   null, { "bSortable": true}, { "bSortable": true}, null,  { "bSortable": false}],
            sZeroRecords: "No users found."},
        "sDom": 'rtlfip'


Now call the function and enjoy.
Hope this will help!!!


To control the synchronous or asynchronous flow, there may be more methods but we will do this by multiple callback mechanism using deferred and promise object.

In order to use this mechanism first we need to have an understanding of deferred and promise object.
Here we will use a promise with a deferred object.
A promise is a placeholder for a result, which is initially unknown. While a deferred represents the computation that results in the value. Every deferred has a promise, which functions as a proxy for the future result.
A promise is a value returned by an asynchronous function, but a deferred can be resolved or rejected by its caller which separates the promise from the resolver.

View original post 44 more words


When we start off as an iOS Developer, we all face a common obstacle ,that is generating the certificates and using it in our apps because Apple does not allow us to debug or run our app without Certificate. So we need an Apple Developer Certificates to develop ,debug and run.

In order to know the types and procedure to use it, first we need to have an understanding of code signing and why it is needed. So lets start with it.

Code signing our app is necessary because due to this only users trust that our app has been created by a source known to Apple. All iOS apps must be code signed and provisioned to launch on a device or to be distributed for testing, or to be submitted to the store.

View original post 277 more words


I received a bug ticket from my client about the unusual behavior of my application UI. It was a problem which was occurring only in iOS7 only.
When the keyboard pops up in iPad devices running on iOS7 the web view of our app gets shrink (app development using Phonegap).

Solution that works for me :
This problem can be solved in few steps.

  1. We need to go to Config.xml and inside the preference tag just need to set the value of KeyboardShrinksView to false.

View original post 77 more words