Sha256: cc6f8e8b87417edb1d8f23d4c6511fee616a5da6e66635b4ae46aac522b64dd0

Contents?: true

Size: 977 Bytes

Versions: 28

Compression:

Stored size: 977 Bytes

Contents

require_dependency "eve_app/application_controller"

module EveApp
  class SimpleResourceController < EveApp::ApplicationController
    class_attribute :allow_index
    class_attribute :includes
    class_attribute :serializer_includes
    # before_action :authenticate_token!

    def index
      if params[:filter] && params[:filter][:id]
        render json: scope.where(id: params[:filter][:id].split(',')), include: serializer_include
      elsif self.allow_index
        render json: scope, include: self.serializer_include
      else
        render :bad_request
      end
    end

    def show
      render json: scope.find(params[:id]) #, include: self.serializer_include
    end

    protected

    def model_name
      self.class.to_s.gsub(/(.+?)Controller/, '\1').singularize.constantize
    end

    def scope
      model_name.includes(self.includes).page(params[:page])
    end

    def serializer_include
      self.serializer_includes || ['*']
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
eve_app-0.1.34 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.33 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.32 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.31 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.29 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.27 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.22 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.21 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.20 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.19 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.18 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.17 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.16 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.14 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.13 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.12 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.11 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.10 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.9 app/controllers/eve_app/simple_resource_controller.rb
eve_app-0.1.8 app/controllers/eve_app/simple_resource_controller.rb