Class: ThinkFeelDoDashboard::MembershipsController

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

Overview

Assigns a participant with a group along with setting the start and end date

Instance Method Summary collapse

Instance Method Details

#createObject

POST /think_feel_do_dashboard/participants/1/groups



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/think_feel_do_dashboard/memberships_controller.rb', line 21

def create
  @membership = @participant
                .memberships
                .build(membership_params)
  authorize! :create, @membership

  if validate_social_membership && @membership.save
    redirect_to participant_path(@participant),
                notice: "Group was successfully assigned"
  else
    render :new
  end
end

#destroyObject

DELETE /think_feel_do_dashboard/participants/1/groups/1



63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/think_feel_do_dashboard/memberships_controller.rb', line 63

def destroy
  authorize! :destroy, @membership
  if @membership.destroy
    redirect_to participant_path(@participant),
                notice: "Group was successfully removed."
  else
    redirect_to participant_path(@participant),
                alert: "There were errors."
  end
end

#editObject

GET /think_feel_do_dashboard/participants/1/groups/1/edit



43
44
45
# File 'app/controllers/think_feel_do_dashboard/memberships_controller.rb', line 43

def edit
  authorize! :edit, @membership
end

#indexObject

GET /think_feel_do_dashboard/participants/1/groups



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

def index
  authorize! :index, Membership
end

#newObject

GET /think_feel_do_dashboard/participants/1/groups/new



15
16
17
18
# File 'app/controllers/think_feel_do_dashboard/memberships_controller.rb', line 15

def new
  @membership = @participant.memberships.build
  authorize! :new, @membership
end

#showObject

GET /think_feel_do_dashboard/participants/1/groups/1



36
37
38
39
40
# File 'app/controllers/think_feel_do_dashboard/memberships_controller.rb', line 36

def show
  redirect_to participant_path(@participant),
              alert: "Membership not found." if @membership.nil?
  authorize! :show, @membership
end

#updateObject

PATCH/PUT /think_feel_do_dashboard/participants/1/groups/1



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/think_feel_do_dashboard/memberships_controller.rb', line 48

def update
  authorize! :update, @membership
  if @membership.update(membership_params)
    redirect_to participant_path(@participant),
                notice: "Group assignment was successfully updated."
  else
    flash[:alert] = @membership.errors.full_messages.join(", ")
    flash[:alert] += "End date cannot be set prior to tomorrow's date. " \
                       "Please use [Discontinue] or [Terminate Access] " \
                       "from the patient dashboard."
    render :edit
  end
end