Commit 8adb9b64 by ivan Lan

Improve params permit code style

parent 76881578
...@@ -39,21 +39,19 @@ module Shotengai ...@@ -39,21 +39,19 @@ module Shotengai
private private
def resource_params def resource_params
spec_value = params.require(resource_key).fetch(:spec_value, nil)&.map(&:permit!) spec_value = params.require(resource_key).fetch(:spec_value, []).map(&:permit!)
info_template = params.require(resource_key).fetch(:info_template, nil)&.map(&:permit!) info_template = params.require(resource_key).fetch(:info_template, []).map(&:permit!)
detail_info_template = params.require(resource_key).fetch(:detail_info_template, nil)&.map(&:permit!) detail_info_template = params.require(resource_key).fetch(:detail_info_template, []).map(&:permit!)
remark_value = params.require(resource_key).fetch(:remark_value, nil)&.map(&:permit!) remark_value = params.require(resource_key).fetch(:remark_value, []).map(&:permit!)
meta = params.require(resource_key).fetch(:meta, nil)&.permit! meta = params.require(resource_key).fetch(:meta, {}).permit!
# ????????!!!!!, spec_value: [:key, :val] 一样的输出值 却在test报错??? # ????????!!!!!, spec_value: [:key, :val] 一样的输出值 却在test报错???
# QUESTION: WARNING: 文档bug吧????? # QUESTION: WARNING: 文档bug吧?????
params.require(resource_key).permit( params.require(resource_key).permit(
:original_price, :price, :stock#, spec_value: [:key, :val] :original_price, :price, :stock#, spec_value: [:key, :val]
).merge( ).merge(
{ spec_value: spec_value, info_template: info_template, remark_value: remark_value,
spec_value: spec_value, info_template: info_template, remark_value: remark_value, detail_info_template: detail_info_template,
detail_info_template: detail_info_template, meta: meta
meta: meta
}
) )
end end
......
...@@ -22,10 +22,10 @@ module Shotengai ...@@ -22,10 +22,10 @@ module Shotengai
private private
def resource_params def resource_params
remark_value = params.require(resource_key).fetch(:remark_value, nil)&.permit! remark_value = params.require(resource_key).fetch(:remark_value, {}).permit!
params.require(resource_key).permit( params.require(resource_key).permit(
:revised_amount :revised_amount
).merge({ remark_value: remark_value }) ).merge(remark_value: remark_value)
end end
def edit_only_unpaid def edit_only_unpaid
......
...@@ -63,10 +63,10 @@ module Shotengai ...@@ -63,10 +63,10 @@ module Shotengai
def resource_params def resource_params
# QUESTION: need these ? # QUESTION: need these ?
# spec = params.require(resource_key).fetch(:spec, nil).try(:permit!) # spec = params.require(resource_key).fetch(:spec, nil).try(:permit!)
spec_template = params.require(resource_key).fetch(:spec_template, nil)&.map(&:permit!) spec_template = params.require(resource_key).fetch(:spec_template, []).map(&:permit!)
remark_template = params.require(resource_key).fetch(:remark_template, nil)&.map(&:permit!) remark_template = params.require(resource_key).fetch(:remark_template, []).map(&:permit!)
detail = params.require(resource_key).fetch(:detail, nil)&.permit! detail = params.require(resource_key).fetch(:detail, {}).permit!
meta = params.require(resource_key).fetch(:meta, nil)&.permit! meta = params.require(resource_key).fetch(:meta, {}).permit!
# NOTE: :catalog_list is a default catalog list for template example, maybe should move it to the template controller, but it need add controller template for every controller # NOTE: :catalog_list is a default catalog list for template example, maybe should move it to the template controller, but it need add controller template for every controller
params.require(resource_key).permit( params.require(resource_key).permit(
:title, :default_series_id, :title, :default_series_id,
...@@ -75,10 +75,8 @@ module Shotengai ...@@ -75,10 +75,8 @@ module Shotengai
# spec_template: [:key, val: []], # spec_template: [:key, val: []],
# remark_template: [:key, :val], # remark_template: [:key, :val],
).merge( ).merge(
{ spec_template: spec_template, remark_template: remark_template,
spec_template: spec_template, remark_template: remark_template, detail: detail, meta: meta
detail: detail, meta: meta
}
) )
end end
end end
......
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