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? before_action :authenticate, if: :json_api_request?
def index def index
@completed_case_logs = CaseLog.where(status: 2) @completed_case_logs = CaseLog.completed
@in_progress_case_logs = CaseLog.where(status: 1) @in_progress_case_logs = CaseLog.in_progress
end end
def create def create

2
app/models/case_log.rb

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

Loading…
Cancel
Save