Sha256: 1b1de2c9a39394d0f2b24b7d69bea2e3e5aa06538f0e196490066c11f265ae1d

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module Kms
  module Catalog
    class CategoriesController < ApplicationController
      def index
        render json: Category.order(:name).to_json(methods: :parent_id, except: :ancestry)
      end

      def create
        category_params.merge!(parent_id: params[:parent_id]) if params[:parent_id]
        @category = Category.new(category_params)
        @category.save
        render json: @category.to_json
      end

      def update
        category_params.merge!(parent_id: params[:parent_id]) if params[:parent_id]
        @category = Category.find(params[:id])
        @category.update_attributes(category_params)
        render json: @category.to_json
      end

      def show
        @category = Category.find(params[:id])
        render json: @category.to_json(methods: :parent_id, except: :ancestry)
      end

      def destroy
        @category = Category.find(params[:id])
        @category.destroy
        render json: @category.to_json
      end

      protected

      def category_params
        params.require(:category).permit!
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kms_catalog-0.5.0 app/controllers/kms/catalog/categories_controller.rb
kms_catalog-0.4.0 app/controllers/kms/catalog/categories_controller.rb