Sha256: 752f70295926ac3333feb9a4cf1ae52e250cae20326d85711ee27a508bb17343

Contents?: true

Size: 1011 Bytes

Versions: 39

Compression:

Stored size: 1011 Bytes

Contents

module Ecom
  module Core
    module Lookupable
      extend ActiveSupport::Concern

      included do
        before_action :set_clazz
      end

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

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

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

      private

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

      def lookup_params
        params.require(:lookup).permit(:name)
      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/lookupable.rb
ecom_core-1.3.13 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.12 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.11 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.10 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.9 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.8 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.7 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.6 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.5 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.4 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.3 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.2 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.1 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.3.0 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.2.36 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.2.35 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.2.34 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.2.33 app/controllers/concerns/ecom/core/lookupable.rb
ecom_core-1.2.32 app/controllers/concerns/ecom/core/lookupable.rb