Sha256: 6380e148d3f3a5d7e85695daeefdd177c089246c571be6476391ba828f69233b

Contents?: true

Size: 1.85 KB

Versions: 23

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pd"

module Renalware
  module PD
    class TrainingSessionsController < BaseController
      def show
        training_session = find_training_session
        authorize training_session
        render locals: { patient: patient, training_session: training_session }
      end

      def new
        training_session = TrainingSession.for_patient(patient).new
        authorize training_session
        render locals: { patient: patient, training_session: training_session }
      end

      def create
        training_session = TrainingSession.for_patient(patient).new(training_session_params)
        authorize training_session
        if training_session.save_by(current_user)
          redirect_to patient_pd_dashboard_path(patient),
            notice: success_msg_for("training_session")
        else
          render :new, locals: { patient: patient, training_session: training_session }
        end
      end

      def edit
        training_session = find_training_session
        authorize training_session
        render locals: { patient: patient, training_session: training_session }
      end

      def update
        training_session = find_training_session
        authorize training_session
        if training_session.update_by(current_user, training_session_params)
          redirect_to patient_pd_dashboard_path(patient),
            notice: success_msg_for("training_session")
        else
          render :edit, locals: { patient: patient, training_session: training_session }
        end
      end

      private

      def find_training_session
        TrainingSession.for_patient(patient).find(params[:id])
      end

      def training_session_params
        params
          .require(:training_session)
          .permit(:training_site_id, :training_type_id, document: {})
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
renalware-core-2.0.77 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.76 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.75 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.74 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.73 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.72 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.71 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.70 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.69 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.68 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.67 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.64 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.63 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.62 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.61 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.60 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.58 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.57 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.56 app/controllers/renalware/pd/training_sessions_controller.rb
renalware-core-2.0.55 app/controllers/renalware/pd/training_sessions_controller.rb