Skip to content

Commit 173d687

Browse files
author
M. Saiqul Haq
committed
model class name should be shought from the set_model_class method first
1 parent 405c331 commit 173d687

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ end
8787
* For `paginator options`, just uncomment the paginator you would like to use, given
8888
the gems bundled in your project. For example, if your models are using `Kaminari`, uncomment `AjaxDatatablesRails::Extensions::Kaminari`. You may remove all commented lines.
8989
* `SimplePaginator` is the most basic of them all, it falls back to passing `offset` and `limit` at the database level (through `ActiveRecord` of course, as that is the only ORM supported for the time being).
90+
9091
* For `sortable_columns`, assign an array of the database columns that correspond to the columns in our view table. For example `[users.f_name, users.l_name, users.bio]`. This array is used for sorting by various columns.
9192

9293
* For `searchable_columns`, assign an array of the database columns that you want searchable by datatables. For example `[users.f_name, users.l_name]`

lib/ajax-datatables-rails/base.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def setup
2121
end
2222

2323
def models
24-
@models
24+
@models ||= AjaxDatatablesRails::Models.new
2525
end
2626

2727
def config
@@ -117,8 +117,8 @@ def build_conditions_for(query)
117117

118118
def search_condition(column, value)
119119
model, column = column.split('.')
120-
model_class = model.singularize.titleize.gsub( / /, '' ).safe_constantize
121-
model_class = models[model] if model_class.nil?
120+
model_class = models[model]
121+
model_class = model.singularize.titleize.gsub( / /, '' ).safe_constantize if model_class.nil?
122122
raise("Model with class name #{model} not found") if model_class.nil?
123123

124124
casted_column = ::Arel::Nodes::NamedFunction.new('CAST', [model_class.arel_table[column.to_sym].as(typecast)])

0 commit comments

Comments
 (0)