Class: Kms::Catalog::CategoriesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/kms/catalog/categories_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

#destroyObject



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

#indexObject



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

#showObject



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

#updateObject



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