Sha256: 485ee576d326aacff9b118dbc58947c1ed29af43112182c1b8fdd79c99360126

Contents?: true

Size: 1.05 KB

Versions: 18

Compression:

Stored size: 1.05 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
      @datatable = find_datatable(params[:id]).try(:new, params[:attributes])
      @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)
      "effective/datatables/#{id}".classify.tap { |klass| klass << 's' if id.to_s.end_with?('s') }.safe_constantize
    end

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

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
effective_datatables-2.1.18 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.16 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.15 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.14 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.13 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.12 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.11 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.10 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.9 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.8 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.7 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.6 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.5 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.4 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.3 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.2 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.1 app/controllers/effective/datatables_controller.rb
effective_datatables-2.1.0 app/controllers/effective/datatables_controller.rb