Sha256: 0fba64081e6dfa2c935d4fb4bec521656b386a566e2b6acc2699c82fa0514aa3

Contents?: true

Size: 1.12 KB

Versions: 14

Compression:

Stored size: 1.12 KB

Contents

module Effective
  class DatatablesController < ApplicationController
    skip_log_page_views quiet: true if defined?(EffectiveLogging)

    # This will respond to both a GET and a POST
    def show
      begin
        @datatable = find_datatable(params[:id]).try(:new) || raise('unable to find datatable')
        @datatable.view = view_context

        EffectiveDatatables.authorize!(self, :index, @datatable.collection_class)

        render json: @datatable.to_json
      rescue => e
        EffectiveDatatables.authorized?(self, :index, @datatable.try(:collection_class))

        render json: error_json(e)
      end
    end

    private

    def find_datatable(id)
      id = id.to_s.gsub(/-\d+\z/, '').gsub('-', '/')
      id.classify.safe_constantize || id.classify.pluralize.safe_constantize
    end

    def error_json(e)
      {
        data: [],
        draw: params[:draw].to_i,
        effective_datatables_error: (e.message.presence unless e.class.name.include?('ActiveRecord::')) || 'unexpected operation',
        recordsTotal: 0,
        recordsFiltered: 0,
        aggregates: [],
        charts: {}
      }
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
effective_datatables-3.6.3 app/controllers/effective/datatables_controller.rb
effective_datatables-3.6.1 app/controllers/effective/datatables_controller.rb
effective_datatables-3.6.0 app/controllers/effective/datatables_controller.rb
effective_datatables-3.5.4 app/controllers/effective/datatables_controller.rb
effective_datatables-3.5.3 app/controllers/effective/datatables_controller.rb
effective_datatables-3.5.2 app/controllers/effective/datatables_controller.rb
effective_datatables-3.5.0 app/controllers/effective/datatables_controller.rb
effective_datatables-3.4.8 app/controllers/effective/datatables_controller.rb
effective_datatables-3.4.7 app/controllers/effective/datatables_controller.rb
effective_datatables-3.4.6 app/controllers/effective/datatables_controller.rb
effective_datatables-3.4.5 app/controllers/effective/datatables_controller.rb
effective_datatables-3.4.4 app/controllers/effective/datatables_controller.rb
effective_datatables-3.4.3 app/controllers/effective/datatables_controller.rb
effective_datatables-3.4.2 app/controllers/effective/datatables_controller.rb