Class: ActiveRecordDataTables
- Inherits:
-
Object
- Object
- ActiveRecordDataTables
- Defined in:
- lib/active-record-data-tables.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(args) ⇒ ActiveRecordDataTables
constructor
A new instance of ActiveRecordDataTables.
- #json(final_query = nil) ⇒ Object
Constructor Details
#initialize(args) ⇒ ActiveRecordDataTables
Returns a new instance of ActiveRecordDataTables.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/active-record-data-tables.rb', line 4 def initialize(args) @args = args @params = @args[:params] @filter_params = @args[:filter_params] @force_filter_for = @args[:force_filter_for] @dts = @params[:dataTables] @columns = @args[:columns] @model = @args[:model] raise "No ':model' was given." unless @model @model_method_name = StringCases.camel_to_snake(@model.name) @joins = {} @sort_columns = [:title, :name] @executed = false end |
Instance Method Details
#execute ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/active-record-data-tables.rb', line 21 def execute @executed = true @query = @model filter sorting limit return @query end |
#json(final_query = nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active-record-data-tables.rb', line 32 def json(final_query = nil) unless final_query execute unless @executed final_query = @query end dis_rec_count = final_query.limit(nil).count dis_rec_count = dis_rec_count.length if dis_rec_count.is_a?(Hash) res = { :sEcho => @dts[:sEcho] ? @dts[:sEcho].to_i : 1, :iTotalRecords => @model.count, :iTotalDisplayRecords => dis_rec_count, :aaData => [] } end |