Class: Kms::Catalog::CategoriesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Kms::Catalog::CategoriesController
- Defined in:
- app/controllers/kms/catalog/categories_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
8 9 10 11 12 13 |
# File 'app/controllers/kms/catalog/categories_controller.rb', line 8 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 |
#destroy ⇒ Object
27 28 29 30 31 |
# File 'app/controllers/kms/catalog/categories_controller.rb', line 27 def destroy @category = Category.find(params[:id]) @category.destroy render json: @category.to_json end |
#index ⇒ Object
4 5 6 |
# File 'app/controllers/kms/catalog/categories_controller.rb', line 4 def index render json: Category.order(:name).to_json(methods: :parent_id, except: :ancestry) end |
#show ⇒ Object
22 23 24 25 |
# File 'app/controllers/kms/catalog/categories_controller.rb', line 22 def show @category = Category.find(params[:id]) render json: @category.to_json(methods: :parent_id, except: :ancestry) end |
#update ⇒ Object
15 16 17 18 19 20 |
# File 'app/controllers/kms/catalog/categories_controller.rb', line 15 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 |