Module: DataTablesController
- Defined in:
- lib/data_tables.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #datatable_source(name) ⇒ Object
-
#datatables_instance_get_value(instance, column) ⇒ Object
gets the value for a column and row.
- #elasticsearch_sanitation(search_string, except) ⇒ Object
Class Method Details
.included(cls) ⇒ Object
4 5 6 |
# File 'lib/data_tables.rb', line 4 def self.included(cls) cls.extend(ClassMethods) end |
Instance Method Details
#datatable_source(name) ⇒ Object
389 390 391 |
# File 'lib/data_tables.rb', line 389 def datatable_source(name) {:action => name, :attrs => method("datatable_#{name}_columns".to_sym).call} end |
#datatables_instance_get_value(instance, column) ⇒ Object
gets the value for a column and row
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/data_tables.rb', line 371 def datatables_instance_get_value(instance, column) if column[:special] special = column[:special] if special[:method] return method(special[:method].to_sym).call(instance) elsif special[:eval] proc = lambda { obj = instance; binding } return Kernel.eval(special[:eval], proc.call) end elsif column[:attribute] val = instance.send(column[:attribute].to_sym) return I18n.t(val.to_s.to_sym, :default => val.to_s) if not val.blank? return '' end return "value not found" end |
#elasticsearch_sanitation(search_string, except) ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/data_tables.rb', line 358 def elasticsearch_sanitation(search_string, except) logger.debug "*** elasticsearch_sanitation.before = `#{search_string}'" search_string = '*' if search_string.blank? search_string.strip! numerical_search = (search_string.split.count > 1) ? "" : "OR *#{search_string.gsub(":","\\:")}*" search_string = "(\"*#{search_string}*\" #{numerical_search}) " unless search_string =~ /(\*|\")/ exceptions = except.map { |f| "NOT #{f[0]}:\"#{f[1]}\""}.join(" AND ") if except search_string += " AND " + exceptions if exceptions logger.debug "*** elasticsearch_sanitation.after = `#{search_string}'" search_string end |