Class: Guts::GroupsController

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

Overview

Groups controller

Instance Method Summary collapse

Instance Method Details

#createObject

Note:

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

Creates a group through post



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

def create
  @group = Group.new group_params
  authorize @group

  if @group.save
    flash[:notice] = 'Group was successfully created.'
    redirect_to edit_group_path(@group)
  else
    render :new
  end
end

#destroyObject

Note:

Redirects to #index on success

Destroys a group



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

def destroy
  authorize @group
  @group.destroy

  flash[:notice] = 'Group was successfully destroyed.'
  redirect_to groups_url
end

#editObject

Editing for a group



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

def edit
  authorize @group
end

#indexObject

Displays a list of groups



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

def index
  @groups = policy_scope(Group).all
end

#newObject

Creation of a new group



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

def new
  @group = Group.new
  authorize @group
end

#showObject

Shows details about a single group



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

def show
  authorize @group
end

#updateObject

Note:

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

Updates a group through patch



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

def update
  authorize @group

  if @group.update(group_params)
    flash[:notice] = 'Group was successfully updated.'
    redirect_to edit_group_path(@group)
  else
    render :edit
  end
end