Class: Notee::CategoriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/notee/categories_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#restrict_access_json, #set_request_filter

Instance Method Details

#createObject



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

#destroyObject



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

#indexObject



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

#showObject



13
14
15
# File 'app/controllers/notee/categories_controller.rb', line 13

def show
  render json: { status: 'success', category: @category }
end

#updateObject



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