Sha256: 407450c9adbd5c9edda719ed4aa32eb059e04337e3891f68db210a225b989a98

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 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
      attributes = (params[:attributes].presence || {}).merge(referer: request.referer)
      scopes = (params[:scopes].presence || {})

      @datatable = find_datatable(params[:id]).try(:new, attributes.merge(scopes))
      @datatable.view = view_context if !@datatable.nil?

      EffectiveDatatables.authorized?(self, :index, @datatable.try(:collection_class))

      respond_to do |format|
        format.html
        format.json {
          if Rails.env.production?
            render json: (@datatable.to_json rescue error_json)
          else
            render json: @datatable.to_json
          end
        }
      end

    end

    private

    def find_datatable(id)
      id.classify.safe_constantize || id.classify.pluralize.safe_constantize
    end

    def error_json
      {
        draw: params[:draw].to_i,
        data: [],
        recordsTotal: 0,
        recordsFiltered: 0,
        aggregates: [],
        charts: {}
      }.to_json
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
effective_datatables-2.12.2 app/controllers/effective/datatables_controller.rb
effective_datatables-2.12.1 app/controllers/effective/datatables_controller.rb
effective_datatables-2.12.0 app/controllers/effective/datatables_controller.rb
effective_datatables-2.11.2 app/controllers/effective/datatables_controller.rb
effective_datatables-2.11.1 app/controllers/effective/datatables_controller.rb
effective_datatables-2.11.0 app/controllers/effective/datatables_controller.rb
effective_datatables-2.10.0 app/controllers/effective/datatables_controller.rb