Commit 507a69ba by ivan Lan

Fix the strength params' bug

parent fbf6aff1
......@@ -30,9 +30,11 @@ module Shotengai
private
def resource_params
remark_input = params.require(resource_key).fetch(:remark_input, nil)&.map(&:permit!)
params.require(resource_key).permit(
:count, :shotengai_series_id, remark_input: [:key, :val]
)
:count, :shotengai_series_id
).merge({ remark_input: remark_input })
end
def edit_only_unpaid
......
......@@ -12,6 +12,7 @@ module Shotengai
params[:product_id] && { shotengai_product_id: params[:product_id] }
)
end
def recycle_bin
page = params[:page] || 1
per_page = params[:per_page] || 10
......@@ -38,12 +39,14 @@ module Shotengai
private
def resource_params
spec = params.require(resource_key).fetch(:spec, nil).try(:permit!)
spec_input = params.require(resource_key).fetch(:spec_input, nil)&.map(&:permit!)
meta = params.require(resource_key).fetch(:meta, nil).try(:permit!)
# ????????!!!!!, spec_input: [:key, :val] 一样的输出值 却在test报错???
# QUESTION: WARNING: 文档bug吧?????
params.require(resource_key).permit(
:original_price, :price, :stock
:original_price, :price, :stock#, spec_input: [:key, :val]
).merge(
{ spec: spec, meta: meta }
{ spec_input: spec_input, meta: meta }
)
end
......
......@@ -62,19 +62,20 @@ module Shotengai
private
def resource_params
# QUESTION: need these ?
spec = params.require(resource_key).fetch(:spec, nil).try(:permit!)
# spec = params.require(resource_key).fetch(:spec, nil).try(:permit!)
spec_input = params.require(resource_key).fetch(:spec_input, nil)&.map(&:permit!)
remark_input = params.require(resource_key).fetch(:remark_input, nil)&.map(&:permit!)
detail = params.require(resource_key).fetch(:detail, nil).try(:permit!)
meta = params.require(resource_key).fetch(:meta, nil).try(:permit!)
remark = params.require(resource_key).fetch(:remark, nil).try(: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,
:need_express, :need_time_attr, :cover_image, catalog_ids: [],
banners: [],
spec_input: [:key, val: []], detail_input: [:key, :val],
meta_input: [:key, :val], remark_input: [:key, :val]
# spec_input: [:key, val: []],
# remark_input: [:key, :val],
).merge(
{ spec: spec, detail: detail, meta: meta, remark: remark }
{ spec_input: spec_input, remark_input: remark_input, detail: detail, meta: meta }
)
end
end
......
......@@ -5,7 +5,7 @@ module Shotengai
end
class_methods do
def hash_columns *columns
def custom_hash_columns *columns
columns.each do |column|
# QUESTION: 这样可以避免 send("#{column}="), 合适?
class_eval %Q{
......@@ -14,8 +14,10 @@ module Shotengai
end
define_method("#{column}_input=") do |val|
parsed_val = val.map{ |h| { (h[:key] || h['key']) => (h[:val] || h['val']) } }.reduce(&:merge)
parsed_val = val && val.map{ |h| { (h[:key] || h['key']) => (h[:val] || h['val']) } }.reduce(&:merge)
self.#{column} = parsed_val
# self.assign_attributes('#{column}' => parsed_val)
end
define_method("#{column}_output") do
......
......@@ -38,7 +38,7 @@ module Shotengai
after_create :set_seq
hash_columns :spec, :meta
custom_hash_columns :spec, :meta
include AASM_DLC
aasm column: :status do
......
......@@ -30,7 +30,7 @@ module Shotengai
require 'acts-as-taggable-on'
self.table_name = 'shotengai_products'
hash_columns :spec, :meta, :detail, :remark
custom_hash_columns :spec, :remark
belongs_to :manager, polymorphic: true, optional: true#, touch: true
validate :check_spec, if: :spec
......
......@@ -29,7 +29,7 @@ module Shotengai
# Using validates_uniqueness_of do not work if the order of Hash is diff
validate :uniq_spec
hash_columns :spec, :meta, :remark
custom_hash_columns :spec, :remark
delegate :title, :detail, :banners, :cover_image, :status, :status_zh, :manager, to: :product
......
......@@ -36,7 +36,7 @@ module Shotengai
validate :check_remark
validates :count, numericality: { only_integer: true, greater_than: 0 }
hash_columns :spec, :meta, :detail, :remark
custom_hash_columns :spec, :meta, :detail, :remark
validate :cannot_edit, if: :order_was_paid
before_destroy :cannot_edit, if: :order_was_paid
......
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