Class: ThinkFeelDoDashboard::GroupsController

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

Overview

Allows for the creation, updating, and deletion of groups

Instance Method Summary collapse

Instance Method Details

#createObject

POST /think_feel_do_dashboard/groups



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

def create
  @group = Group.new(group_params.except(:user_id))
  authorize! :create, @group

  if @group.save
    redirect_to @group,
                notice: "Group was successfully created."
  else
    render :new
  end
end

#destroyObject

DELETE /think_feel_do_dashboard/groups/1



59
60
61
62
63
64
65
66
67
# File 'app/controllers/think_feel_do_dashboard/groups_controller.rb', line 59

def destroy
  authorize! :destroy, @group
  @group.destroy
  response_status = { notice: "Group was successfully destroyed." }
rescue ActiveRecord::DeleteRestrictionError => e
  response_status = { alert: e.message }
ensure
  redirect_to groups_url, response_status
end

#editObject

GET /think_feel_do_dashboard/groups/1/edit



42
43
44
# File 'app/controllers/think_feel_do_dashboard/groups_controller.rb', line 42

def edit
  authorize! :edit, @group
end

#indexObject

GET /think_feel_do_dashboard/groups



12
13
14
15
# File 'app/controllers/think_feel_do_dashboard/groups_controller.rb', line 12

def index
  authorize! :index, Group
  @groups = Group.all
end

#newObject

GET /think_feel_do_dashboard/groups/new



31
32
33
34
# File 'app/controllers/think_feel_do_dashboard/groups_controller.rb', line 31

def new
  authorize! :new, Group
  @group = Group.new
end

#showObject

GET /think_feel_do_dashboard/groups/1



37
38
39
# File 'app/controllers/think_feel_do_dashboard/groups_controller.rb', line 37

def show
  authorize! :show, @group
end

#updateObject

PATCH/PUT /think_feel_do_dashboard/groups/1



47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/think_feel_do_dashboard/groups_controller.rb', line 47

def update
  authorize! :update, @group
  if @group.update(group_params.except(:user_id))
    redirect_to group_path(@group),
                notice: "Group was successfully updated.",
                only: true
  else
    render :edit
  end
end