Sha256: b8863a357c427036fd4202882cee2341a232ba45b052afd91d7b0bd485d5785d

Contents?: true

Size: 1.29 KB

Versions: 16

Compression:

Stored size: 1.29 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) || @datatable.try(: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_plural = id.pluralize == id && id.singularize != id
      klass = "effective/datatables/#{id}".classify

      (id_plural ? klass.pluralize : klass).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

16 entries across 16 versions & 1 rubygems

Version Path
effective_datatables-2.6.21 app/controllers/effective/datatables_controller.rb
effective_datatables-2.9.0 app/controllers/effective/datatables_controller.rb
effective_datatables-2.8.0 app/controllers/effective/datatables_controller.rb
effective_datatables-2.7.0 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.20 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.19 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.18 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.17 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.16 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.15 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.14 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.13 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.12 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.11 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.10 app/controllers/effective/datatables_controller.rb
effective_datatables-2.6.9 app/controllers/effective/datatables_controller.rb