Sha256: b5caa51cfbd6c7a2eb6cae48047e812efc32f7485d44f434ac7d2423fd8efdc6

Contents?: true

Size: 1.11 KB

Versions: 29

Compression:

Stored size: 1.11 KB

Contents

module Ecom
  module Core
    module ResourceTypeable
      extend ActiveSupport::Concern

      included do
        before_action :set_clazz
      end

      def index
        render json: ResourceTypeSerializer.new(@clazz.all)
      end

      def create
        resource_type = @clazz.new(resource_type_params)
        if resource_type.save
          render json: ResourceTypeSerializer.new(resource_type), status: :created
        else
          render json: { success: false, errors: resource_type.errors }, status: :unprocessable_entity
        end
      end

      def update
        resource_type = @clazz.find(params[:id])
        if resource_type.update(resource_type_params)
          render json: ResourceTypeSerializer.new(resource_type)
        else
          render json: { success: false, errors: resource_type.errors }, status: :unprocessable_entity
        end
      end

      private

      def set_clazz
        @clazz = "Ecom::Core::#{controller_name.classify}".constantize
      end

      def resource_type_params
        params.require(:resource_type).permit(:code, :name, :base_unit)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
ecom_core-1.1.2 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.1.1 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.1.0 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.25 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.24 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.23 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.22 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.21 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.20 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.19 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.18 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.17 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.16 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.15 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.14 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.13 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.12 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.11 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.10 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.0.9 app/controllers/concerns/ecom/core/resource_typeable.rb