Sha256: 2f139a18cf7ee57387ae9617c48cc40616b8a1194b9981aa7ab3280691cd2b76

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module Kms
  module Catalog
    class ProductsController < ApplicationController
      def index
        render json: Product.order(:name)
      end

      def create
        product_params[:category_ids] = product_params[:category_ids].split(',') if product_params[:category_ids]
        @product = Product.new(product_params)
        @product.save
        render json: @product
      end

      def update
        product_params[:category_ids] = product_params[:category_ids].split(',') if product_params[:category_ids]
        @product = Product.find(params[:id])
        @product.update_attributes(product_params)
        render json: @product
      end

      def show
        @product = Product.find(params[:id])
        render json: @product
      end

      def destroy
        @product = Product.find(params[:id])
        @product.destroy
        render json: @product
      end

      protected

      def product_params
        params.require(:product).permit(:name, :description, :category_ids, :seo_title, :seo_keywords, :seo_description, master_attributes: [:price, :image, :id])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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