Sha256: 25ad91a206dcf87be24dcd9d44b88edbe1852da18477f289895757fbd83cdf08

Contents?: true

Size: 1.13 KB

Versions: 92

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Renalware
  module Problems
    class NotesController < BaseController
      before_action :load_patient

      def index
        load_problem
        render_index
      end

      def new
        load_problem
        note = @problem.notes.new
        render_form(note, url: patient_problem_notes_path(patient, @problem))
      end

      def create
        load_problem
        note = @problem.notes.create(notes_params)

        if note.save
          render_index
        else
          render_form(note, url: patient_problem_notes_path(patient, @problem))
        end
      end

      private

      def load_problem
        @problem = patient.problems.find(params[:problem_id])
      end

      def render_index
        render "index", locals: { problem: @problem, notes: notes }
      end

      def render_form(note, url:)
        render "form", locals: { problem: @problem, note: note, url: url }
      end

      def notes_params
        params.require(:problems_note).permit(:description).merge(by: current_user)
      end

      def notes
        @notes ||= @problem.notes.ordered
      end
    end
  end
end

Version data entries

92 entries across 92 versions & 1 rubygems

Version Path
renalware-core-2.0.116 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.115 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.113 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.112 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.111 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.110 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.109 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.108 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.106 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.105 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.104 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.103 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.102 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.101 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.100 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.99 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.98 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.97 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.96 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.95 app/controllers/renalware/problems/notes_controller.rb