Class: CategoriesController

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

Overview

The categories controller

Instance Method Summary collapse

Methods inherited from ApplicationController

#system

Instance Method Details

#createObject

Create a category


20
21
22
23
# File 'app/controllers/categories_controller.rb', line 20

def create
  category = Category.new
  category.attributes = params.require(:category).permit(:name)
end

#destroyObject

Destroy a category


31
32
33
# File 'app/controllers/categories_controller.rb', line 31

def destroy
  @category.destroy
end

#indexObject

SHows all categories


10
11
12
# File 'app/controllers/categories_controller.rb', line 10

def index
  render json: Category.all
end

#showObject

SHow a single category


15
16
17
# File 'app/controllers/categories_controller.rb', line 15

def show
  render json: @category
end

#updateObject

Edit a category


26
27
28
# File 'app/controllers/categories_controller.rb', line 26

def update
  @category.attributes = params.require(:category).permit(:name)
end