我有一些模型,其中包含以下代码:
appraisal_detail.each_value { |detail|
# some code...
}
它使用消息“未定义的方法'each_value'”引发 NoMethodError。我做错什么了吗?欢迎大家提出意见。
以下是引发错误的方法的完整内容:
def self.update_appraisal_details(appraisal, appraisal_detail)
status = true
appraisal_detail_ids = appraisal.employee_appraisal_detail_ids
appraisal_detail.each_value { |detail|
appraisal_detail = find_by_employee_appraisal_id_and_kra_list_id(appraisal.id, detail[:kra_list_id])
if appraisal_detail.nil? # For newly added KRA
new_detail = EmployeeAppraisalDetail.new(detail.merge({:employee_appraisal_id => appraisal.id}))
status = (new_detail.save && status)
elsif appraisal_detail.status == "Inactive"
status = (appraisal_detail.update_attributes(:status => "Active") && status)
appraisal_detail_ids.delete(appraisal_detail.id)
else
appraisal_detail_ids.delete(appraisal_detail.id)
end
}
end