Sha256: 767f8e8c450fb534daf9d43f3ea2cf25bfe4cc072ee422f38c0174d4f6486159

Contents?: true

Size: 1.76 KB

Versions: 21

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/research"

module Renalware
  module Research
    class StudiesController < BaseController
      include Renalware::Concerns::Pageable

      def index
        studies = Study.ordered.page(page).per(per_page)
        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,
            :application_url
          )
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
renalware-core-2.0.51 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.50 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.48 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.47 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.46 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.45 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.44 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.43 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.42 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.41 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.40 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.39 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.38 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.37 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.36 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.35 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.34 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.33 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.32 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.31 app/controllers/renalware/research/studies_controller.rb