Sha256: 1dfd5cd8841c35f2eaeeb0a2f3be64d128bb7e63f67fcb9b339b6ae2b458e163
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
module Ecom module Model 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::Model::#{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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ecom_model-2.0.4 | app/controllers/concerns/ecom/model/resource_typeable.rb |