Class: ThinkFeelDoEngine::ParticipantDataController

Inherits:
ApplicationController show all
Includes:
Concerns::NavigatorEnabled
Defined in:
app/controllers/think_feel_do_engine/participant_data_controller.rb

Overview

Provides generic create and update methods for a participant’s resources.

Constant Summary

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/think_feel_do_engine/participant_data_controller.rb', line 13

def create
  @data = current_participant.build_data_record(association, attributes)

  if @data.save
    flash[:notice] = provider.data_class_name.titleize + " saved"

    respond_to do |format|
      format.html { redirect_to navigator_next_content_url }
      format.js { render status: 201 }
    end
  else
    respond_with_error
  end

rescue RuntimeError => e
  respond_with_error e
end

#updateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/think_feel_do_engine/participant_data_controller.rb', line 31

def update
  @data = current_participant
          .fetch_data_record(association, attributes[:id])

  if @data.update(attributes.reject { |a| a == "id" })
    flash[:notice] = provider.data_class_name.titleize + " saved"

    respond_to do |format|
      format.html { redirect_to navigator_next_content_url }
      format.js {}
    end
  else
    respond_with_error
  end

rescue RuntimeError => e
  respond_with_error e
end