Class: ThinkFeelDoEngine::Participants::AssessmentsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/think_feel_do_engine/participants/assessments_controller.rb

Overview

Authorizes and manages Assessment administration.

Constant Summary collapse

ASSESSMENT_TYPES =
{ phq9: PhqAssessment, wai: WaiAssessment }.freeze

Constants inherited from ApplicationController

ApplicationController::CSRF_COOKIE_NAME, ApplicationController::CSRF_HEADER_NAME, ApplicationController::INACTIVE_MESSAGE, ApplicationController::ROOT_URI

Instance Method Summary collapse

Methods inherited from ApplicationController

#access_denied_resource_path, #after_sign_in_path_for, #after_sign_out_path_for, #raise_not_found!, #render_not_found

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/think_feel_do_engine/participants/assessments_controller.rb', line 19

def create
  @assessment = build_assessment(assessment_params)

  if @assessment.save
    flash.now[:notice] = "Assessment saved"

    if available_token
      @token = available_token
      @assessment = build_assessment(release_date: @token.release_date)

      render "think_feel_do_engine/participants/assessments/" \
             "new_#{assessment_name}"
    else
      render :success
    end
  else
    errors = @assessment.errors.full_messages.join(", ")
    flash.now[:alert] = "Unable to save assessment: #{errors}"
    render "think_feel_do_engine/participants/assessments/" \
           "new_#{assessment_name}"
  end
end

#newObject



12
13
14
15
16
17
# File 'app/controllers/think_feel_do_engine/participants/assessments_controller.rb', line 12

def new
  @assessment = build_assessment(release_date: @token.release_date)

  render "think_feel_do_engine/participants/assessments/" \
         "new_#{assessment_name}"
end