Sha256: 54060b785272b7447cf996683d206519ee90c3c15314b0e8ebd5b1235cbf1e96

Contents?: true

Size: 1.03 KB

Versions: 39

Compression:

Stored size: 1.03 KB

Contents

module Ecom
  module Core
    module ResourceTypeable
      extend ActiveSupport::Concern

      included do
        before_action :set_clazz
      end

      def index
        render json: @clazz.all
      end

      def create
        resource_type = @clazz.new(resource_type_params)
        if resource_type.save
          render json: 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: 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

39 entries across 39 versions & 1 rubygems

Version Path
ecom_core-1.3.14 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.13 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.12 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.11 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.10 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.9 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.8 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.7 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.6 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.5 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.4 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.3 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.2 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.1 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.3.0 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.2.36 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.2.35 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.2.34 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.2.33 app/controllers/concerns/ecom/core/resource_typeable.rb
ecom_core-1.2.32 app/controllers/concerns/ecom/core/resource_typeable.rb