Sha256: d5c6fcf92a796e7b0236fb212b6eb2093f25010e6c0c456d4a1b5d79a09a3a3d

Contents?: true

Size: 1.6 KB

Versions: 12

Compression:

Stored size: 1.6 KB

Contents

require_dependency "renalware/research"

module Renalware
  module Research
    class StudiesController < BaseController
      def index
        studies = Study.ordered
        authorize studies
        render locals: { studies: studies }
      end

      def new
        study = Study.new
        authorize study
        render_new(study)
      end

      def create
        study = Study.new(study_params)
        authorize study
        if study.save_by(current_user)
          redirect_to research_studies_path, notice: success_msg_for("clinical study")
        else
          render_new(study)
        end
      end

      def edit
        study = find_and_authorize_study
        render_edit(study)
      end

      def update
        study = find_and_authorize_study
        if study.update_by(current_user, study_params)
          redirect_to research_studies_path, notice: success_msg_for("clinical study")
        else
          render_edit(study)
        end
      end

      def destroy
        study = find_and_authorize_study
        study.destroy!
        redirect_to research_studies_path, notice: success_msg_for("clinical study")
      end

      private

      def find_and_authorize_study
        Study.find(params[:id]).tap { |study| authorize study }
      end

      def render_new(study)
        render :new, locals: { study: study }
      end

      def render_edit(study)
        render :edit, locals: { study: study }
      end

      def study_params
        params
          .require(:research_study)
          .permit(:code, :description, :leader, :notes, :started_on, :terminated_on)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.rc7 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.rc6 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.rc5 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.rc4 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.rc3 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.rc1 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.0.pre.beta12 app/controllers/renalware/research/studies_controller.rb