Browse Source

Use scopes for bulk status lookups

pull/51/head
baarkerlounger 3 years ago
parent
commit
f211373ffa
  1. 4
      app/controllers/case_logs_controller.rb
  2. 2
      app/models/case_log.rb

4
app/controllers/case_logs_controller.rb

@ -3,8 +3,8 @@ class CaseLogsController < ApplicationController
before_action :authenticate, if: :json_api_request?
def index
@completed_case_logs = CaseLog.where(status: 2)
@in_progress_case_logs = CaseLog.where(status: 1)
@completed_case_logs = CaseLog.completed
@in_progress_case_logs = CaseLog.in_progress
end
def create

2
app/models/case_log.rb

@ -28,6 +28,8 @@ end
class CaseLog < ApplicationRecord
include Discard::Model
default_scope -> { kept }
scope :in_progress, -> { where(status: "in_progress") }
scope :completed, -> { where(status: "completed") }
validate :instance_validations
before_save :update_status!

Loading…
Cancel
Save