Class: AjaxDatatablesRails

Inherits:
Object
  • Object
show all
Defined in:
lib/ajax-datatables-rails.rb

Overview

require ‘rails’

Defined Under Namespace

Classes: MethodError

Constant Summary collapse

VERSION =
'0.0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ AjaxDatatablesRails

Returns a new instance of AjaxDatatablesRails.



11
12
13
# File 'lib/ajax-datatables-rails.rb', line 11

def initialize(view)
  @view = view
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



15
16
17
# File 'lib/ajax-datatables-rails.rb', line 15

def method_missing(meth, *args, &block)
  @view.send(meth, *args, &block)
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



9
10
11
# File 'lib/ajax-datatables-rails.rb', line 9

def columns
  @columns
end

#model_nameObject (readonly)

Returns the value of attribute model_name.



9
10
11
# File 'lib/ajax-datatables-rails.rb', line 9

def model_name
  @model_name
end

#searchable_columnsObject (readonly)

Returns the value of attribute searchable_columns.



9
10
11
# File 'lib/ajax-datatables-rails.rb', line 9

def searchable_columns
  @searchable_columns
end

Instance Method Details

#as_json(options = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/ajax-datatables-rails.rb', line 19

def as_json(options = {})
  {
    sEcho: params[:sEcho].to_i,
    iTotalRecords: @model_name.count,
    iTotalDisplayRecords: filtered_record_count,
    aaData: data
  }
end