Skip to content

Commit 9d2ff10

Browse files
author
Joel Quenneville
committed
changed the class variables over to instance variables and updated the template"
1 parent 10b13f0 commit 9d2ff10

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

lib/ajax-datatables-rails.rb

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,11 @@ class AjaxDatatablesRails
44

55
VERSION = '0.0.1'
66

7-
class << self
8-
9-
def columns(column_array)
10-
@@columns ||= column_array
11-
end
12-
13-
def model_name(model_name)
14-
@@model_name ||= model_name
15-
end
16-
17-
def searchable_columns(columns_array)
18-
@@searchable_columns ||= columns_array
19-
end
20-
21-
end
22-
237
def initialize(view)
248
@view = view
259
end
10+
11+
attr_reader :columns, :model_name, :searchable_columns
2612

2713
def method_missing(meth, *args, &block)
2814
@view.send(meth, *args, &block)
@@ -31,7 +17,7 @@ def method_missing(meth, *args, &block)
3117
def as_json(options = {})
3218
{
3319
sEcho: params[:sEcho].to_i,
34-
iTotalRecords: @@model_name.count,
20+
iTotalRecords: @model_name.count,
3521
iTotalDisplayRecords: get_raw_records.count,
3622
aaData: data
3723
}
@@ -57,7 +43,7 @@ def sort_records(records)
5743

5844
def search_records(records)
5945
if params[:sSearch].present?
60-
query = @@searchable_columns.map do |column|
46+
query = @searchable_columns.map do |column|
6147
"#{column} LIKE :search"
6248
end.join(" OR ")
6349
records = records.where(query, search: "%#{params[:sSearch]}%")
@@ -74,7 +60,7 @@ def per_page
7460
end
7561

7662
def sort_column
77-
@@columns[params[:iSortCol_0].to_i]
63+
@columns[params[:iSortCol_0].to_i]
7864
end
7965

8066
def sort_direction

lib/generators/ajaxdatatable/templates/datatable.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
class <%= model.classify.pluralize %>Datatable < AjaxDatatablesRails
2-
model_name <%= model.classify %>
3-
columns # insert array of column names here
4-
searchable_columns #insert array of columns that will be searched
2+
3+
def initialize(view)
4+
@model_name = <%= model.classify %>
5+
@columns = # insert array of column names here
6+
@searchable_columns = #insert array of columns that will be searched
7+
super(view)
8+
end
59

610
private
711

0 commit comments

Comments
 (0)