Class: Notee::CategoriesController
Instance Method Summary
collapse
#restrict_access_json, #set_request_filter
Instance Method Details
#create ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/notee/categories_controller.rb', line 17
def create
@category = Category.new(category_params)
respond_to do |format|
if @category.save
format.json { render json: @category, status: 200 }
else
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
|
#destroy ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'app/controllers/notee/categories_controller.rb', line 41
def destroy
respond_to do |format|
if @category.update(slug: nil, is_deleted: true)
Category.before_destroy_parent(@category.id)
format.json { render json: @category, status: 200 }
else
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
|
#index ⇒ Object
8
9
10
11
|
# File 'app/controllers/notee/categories_controller.rb', line 8
def index
@categories = Category.where(is_deleted: false)
render json: { status: 'success', categories: @categories }
end
|
#show ⇒ Object
13
14
15
|
# File 'app/controllers/notee/categories_controller.rb', line 13
def show
render json: { status: 'success', category: @category }
end
|
#update ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/controllers/notee/categories_controller.rb', line 28
def update
respond_to do |format|
Category.skip_callback(:save, :before, :set_slug)
if @category.update(category_params)
Category.set_callback(:save, :before, :set_slug)
format.json { render json: @category, status: 200 }
else
Category.set_callback(:save, :before, :set_slug)
format.json { render json: @category.errors, status: :unprocessable_entity }
end
end
end
|