Commit 366eeba3 by ivan Lan

Improve snapshot remark

parent 25adb8bd
...@@ -22,9 +22,10 @@ module Shotengai ...@@ -22,9 +22,10 @@ module Shotengai
private private
def resource_params def resource_params
remark_input = params.require(resource_key).fetch(:remark_input, nil)&.map(&:permit!)
params.require(resource_key).permit( params.require(resource_key).permit(
:revised_amount :revised_amount
) ).merge({ remark_input: remark_input })
end end
def edit_only_unpaid def edit_only_unpaid
......
...@@ -180,10 +180,11 @@ module Shotengai ...@@ -180,10 +180,11 @@ module Shotengai
def check_remark def check_remark
errors.add(:remark, 'remark 必须是个 Hash') unless remark.is_a?(Hash) errors.add(:remark, 'remark 必须是个 Hash') unless remark.is_a?(Hash)
nullable_key = series.remark.select{ |k, v| v }.keys nullable_keys = series.remark.select{ |k, v| v }.keys
required_key = product.remark.keys - nullable_key required_keys = product.remark.keys - nullable_keys
absent_keys = required_keys - remark.keys
# remark 可添加多余字段 # remark 可添加多余字段
errors.add(:remark, '非法的关键字,或关键字缺失') unless (required_key - remark.keys).empty? errors.add(:remark, "必填remark值为空, #{absent_keys}") unless absent_keys.empty?
end end
# NOTE: Shotengai::Snapshot.find_by_id(self.id) to get the self before changed # NOTE: Shotengai::Snapshot.find_by_id(self.id) to get the self before changed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment