module Ecom module Core module Lookupable extend ActiveSupport::Concern included do before_action :set_clazz end def index render json: ResourceTypeSerializer.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