Commit 8adb9b64 by ivan Lan

Improve params permit code style

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