Class: Guts::TypesController

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

Overview

Types controller

Instance Method Summary collapse

Instance Method Details

#createObject

Note:

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

Creates a type through post



31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/guts/types_controller.rb', line 31

def create
  @type = Type.new type_params
  authorize @type

  if @type.save
    flash[:notice] = 'Type was successfully created.'
    redirect_to edit_type_path(@type)
  else
    render :new
  end
end

#destroyObject

Note:

Redirects to #index on success

Destroys a single type



58
59
60
61
62
63
64
# File 'app/controllers/guts/types_controller.rb', line 58

def destroy
  authorize @type
  @type.destroy

  flash[:notice] = 'Type was successfully destroyed.'
  redirect_to types_path
end

#editObject

Editing of a type



25
26
27
# File 'app/controllers/guts/types_controller.rb', line 25

def edit
  authorize @type
end

#indexObject

Display a list of types



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

def index
  @types = policy_scope(Type).all
end

#newObject

Creation of a type



19
20
21
22
# File 'app/controllers/guts/types_controller.rb', line 19

def new
  @type = Type.new
  authorize @type
end

#showObject

Show details about a single type



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

def show
  authorize @type
end

#updateObject

Note:

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

Updates a type through patch



45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/guts/types_controller.rb', line 45

def update
  authorize @type

  if @type.update type_params
    flash[:notice] = 'Type was successfully updated.'
    redirect_to edit_type_path(@type)
  else
    render :edit
  end
end