Class: Guts::CategoriesController

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

Overview

Categories controller

Instance Method Summary collapse

Methods included from SessionsHelper

#current_user, #log_in, #log_out, #logged_in?

Instance Method Details

#createObject

Note:

Redirects to #index if successfull or re-renders #new if not

Creates a category through post



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

def create
  @category = Category.new category_params

  if @category.save
    redirect_to categories_path, notice: "Category was successfully created."
  else
    render :new
  end
end

#destroyObject

Note:

Redirects to #index on success

Destroys a category



50
51
52
53
# File 'app/controllers/guts/categories_controller.rb', line 50

def destroy
  @category.destroy
  redirect_to categories_path, notice: "Category was successfully destroyed."
end

#editObject

Editing for a category



23
24
# File 'app/controllers/guts/categories_controller.rb', line 23

def edit
end

#indexObject

Displays a list of categories



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

def index
  @categories = Category.all
end

#newObject

Creation of a new category



18
19
20
# File 'app/controllers/guts/categories_controller.rb', line 18

def new
  @category = Category.new
end

#showObject

Shows details about a single category



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

def show
end

#updateObject

Note:

Redirects to #index if successfull or re-renders #edit if not

Updates a category through patch



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

def update
  if @category.update category_params
    redirect_to categories_path, notice: "Category was successfully updated."
  else
    render :edit
  end
end