Sha256: 6b52d16bb8beb326735b6864e78630fa4ac467883d88776dd3d40014564adeee

Contents?: true

Size: 1.93 KB

Versions: 97

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/research"

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

      def index
        query = Study.ordered.ransack(params[:q])
        studies = query.result.page(page).per(per_page)
        authorize studies
        render locals: { studies: studies, query: query }
      end

      def show
        study = find_and_authorize_study
        render locals: { study: study }
      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_study_path(study), 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

97 entries across 97 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.1.0 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.167 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.166 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.165 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.164 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.163 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.162 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.161 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.160 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.159 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.158 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.157 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.156 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.155 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.153 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.152 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.151 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.149 app/controllers/renalware/research/studies_controller.rb
renalware-core-2.0.148 app/controllers/renalware/research/studies_controller.rb