Class: Notee::CategoriesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/notee/categories_controller.rb', line 18

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



39
40
41
42
43
44
45
46
47
# File 'app/controllers/notee/categories_controller.rb', line 39

def destroy
  respond_to do |format|
    if @category.destroy
      format.json { render json: @category, status: 200 }
    else
      format.json { render json: @category.errors, status: :internal_server_error }
    end
  end
end

#indexObject



8
9
10
11
# File 'app/controllers/notee/categories_controller.rb', line 8

def index
  @categories = Category.all
  render json: { status: 'success', categories: @categories}
end

#showObject



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

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

#updateObject



29
30
31
32
33
34
35
36
37
# File 'app/controllers/notee/categories_controller.rb', line 29

def update
  respond_to do |format|
    if @category.update(category_params)
      format.json { render json: @category, status: 200 }
    else
      format.json { render json: @category.errors, status: :unprocessable_entity }
    end
  end
end