在 apps/models/concerns/deactivable.rb 中
module Deactivatable
extend ActiveSupport::Concern
included do
scope :alive, -> { where(:deactivated_at => nil) }
end
def deactivate(t = Time.current)
update_attribute(:deactivated_at,t)
end
def activate
update_attribute(:deactivated_at,nil)
end
def deactivated?
deactivated_at.present?
end
end
Run Code Online (Sandbox Code Playgroud)
这包含在 2 个模型中:app/models/activity_rules/activity_detection_rule.rb 和 app/models/concerns/generic_campaign.rb。
还有 2 个模型包含相同的方法,但属性名称不同。
在可赎回.rb中,
class Redeemable < ActiveRecord::Base
scope :alive, -> { where("(deactivation_date is null) and (expiry_date is null or expiry_date >= ?)",Date.today) }
def deactivate(t = Time.current)
update_attribute(:deactivation_date,t)
end
def reactivate
update_attribute(:deactivation_date,nil)
end
def deactivated?
deactivation_date.present?
end
end
Run Code Online (Sandbox Code Playgroud)
并在surprise_set.rb中
scope :alive, …Run Code Online (Sandbox Code Playgroud) 在sidekiq_batch.rb中,
def sidekiq_status
begin
something
rescue => e
Rails.logger.error("\nRESCUENIL in sidekiq_status #{e.class} #{e.message} in #{e.backtrace}")
# FIXME RESCUENIL
nil
end
end
Run Code Online (Sandbox Code Playgroud)
在checkin.rb中,
def attached_receipt_image
begin
something else
rescue => e
Rails.logger.error("\nRESCUENIL in attached_receipt_image #{e.class} #{e.message} in #{e.backtrace}")
# FIXME RESCUENIL
nil
end
end
Run Code Online (Sandbox Code Playgroud)
在barcode.rb中,
def receipt_check?
begin
some code
rescue => e
Rails.logger.error("\nRESCUENIL in receipt_check #{e.class} #{e.message} in #{e.backtrace}")
# FIXME RESCUENIL
nil
end
end
Run Code Online (Sandbox Code Playgroud)
需要干掉代码.如何在模型中为所有这些方法编写常见的错误记录例程?