所以我真的很难做到这一点......基本上我想要做的是保存或创建程序记录时我想检查状态是否设置为已完成。然后如果是,则继续创建关联的事务记录,其中包含来自过程记录的详细信息。但是我一直在*** NoMethodError Exception: undefined method
为 nil:NilClass"` 创建一个"`
只是不知道去哪里!!
class Procedure < ActiveRecord::Base
store_accessor :properties, :tooth, :buccal, :mesial, :occlusal, :distal, :lingual
belongs_to :item
belongs_to :patient
belongs_to :practice
belongs_to :provider
belongs_to :operatory
belongs_to :appointment
belongs_to :transaction
before_create :create_transaction
before_save :create_transaction
before_save :check_if_was_marked_as_complete
validates :item, :patient, :provider, :date, presence: true
validates_associated :item, :patient, :provider
private
def create_transaction
if status == "completed"
transaction.create do |t|
t.amount = fee
#t.practice = self.practice
t.debit_account = patient.family.account
t.credit_account = provider.revenue_account
#t.patient = self.patient
end
end
end
def check_if_was_marked_as_complete
if self.status_was == "completed"
return false
else
return true
end
end
end
编辑*我的方法现在看起来像这样
def create_association
if status == "completed"
create_transaction do |t|
t.amount = fee
#t.practice = self.practice
t.debit_account = patient.family.account
t.credit_account = provider.revenue_account
#t.patient = self.patient
end
end
end