Commit 52c76607 by ivan Lan

Add info to product, series and snapshot

parent 1675501c
...@@ -39,6 +39,7 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1] ...@@ -39,6 +39,7 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
t.string :type t.string :type
t.json :meta t.json :meta
t.json :remark t.json :remark
t.json :info
t.references :shotengai_product, foreign_key: true t.references :shotengai_product, foreign_key: true
t.timestamps t.timestamps
...@@ -88,6 +89,7 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1] ...@@ -88,6 +89,7 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
t.string :type t.string :type
t.json :meta t.json :meta
t.json :remark t.json :remark
t.json :info
t.references :shotengai_series, foreign_key: true t.references :shotengai_series, foreign_key: true
t.references :shotengai_order, foreign_key: true t.references :shotengai_order, foreign_key: true
......
...@@ -40,13 +40,14 @@ module Shotengai ...@@ -40,13 +40,14 @@ module Shotengai
private private
def resource_params def resource_params
spec_input = params.require(resource_key).fetch(:spec_input, nil)&.map(&:permit!) spec_input = params.require(resource_key).fetch(:spec_input, nil)&.map(&:permit!)
info_input = params.require(resource_key).fetch(:info_input, nil)&.map(&:permit!)
meta = params.require(resource_key).fetch(:meta, nil).try(:permit!) meta = params.require(resource_key).fetch(:meta, nil).try(:permit!)
# ????????!!!!!, spec_input: [:key, :val] 一样的输出值 却在test报错??? # ????????!!!!!, spec_input: [:key, :val] 一样的输出值 却在test报错???
# QUESTION: WARNING: 文档bug吧????? # QUESTION: WARNING: 文档bug吧?????
params.require(resource_key).permit( params.require(resource_key).permit(
:original_price, :price, :stock#, spec_input: [:key, :val] :original_price, :price, :stock#, spec_input: [:key, :val]
).merge( ).merge(
{ spec_input: spec_input, meta: meta } { spec_input: spec_input, info_input: info_input, meta: meta }
) )
end end
......
...@@ -65,6 +65,7 @@ module Shotengai ...@@ -65,6 +65,7 @@ module Shotengai
# 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!) spec_input = params.require(resource_key).fetch(:spec_input, nil)&.map(&:permit!)
remark_input = params.require(resource_key).fetch(:remark_input, nil)&.map(&:permit!) remark_input = params.require(resource_key).fetch(:remark_input, nil)&.map(&:permit!)
info_input = params.require(resource_key).fetch(:info_input, nil)&.map(&:permit!)
detail = params.require(resource_key).fetch(:detail, nil).try(:permit!) detail = params.require(resource_key).fetch(:detail, nil).try(:permit!)
meta = params.require(resource_key).fetch(:meta, nil).try(:permit!) meta = params.require(resource_key).fetch(:meta, 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 # 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
...@@ -75,7 +76,10 @@ module Shotengai ...@@ -75,7 +76,10 @@ module Shotengai
# spec_input: [:key, val: []], # spec_input: [:key, val: []],
# remark_input: [:key, :val], # remark_input: [:key, :val],
).merge( ).merge(
{ spec_input: spec_input, remark_input: remark_input, detail: detail, meta: meta } {
spec_input: spec_input, remark_input: remark_input, info_input: info_input,
detail: detail, meta: meta
}
) )
end end
end end
......
...@@ -24,6 +24,10 @@ module Shotengai ...@@ -24,6 +24,10 @@ module Shotengai
} }
end end
end end
def hash_column
# like meta, detail these json using for code development
end
end end
end end
end end
\ No newline at end of file
...@@ -31,7 +31,7 @@ module Shotengai ...@@ -31,7 +31,7 @@ module Shotengai
require 'acts-as-taggable-on' require 'acts-as-taggable-on'
self.table_name = 'shotengai_products' self.table_name = 'shotengai_products'
custom_hash_columns :spec, :remark custom_hash_columns :spec, :remark, :info
belongs_to :manager, polymorphic: true, optional: true#, touch: true belongs_to :manager, polymorphic: true, optional: true#, touch: true
validate :check_spec, if: :spec validate :check_spec, if: :spec
......
...@@ -29,7 +29,7 @@ module Shotengai ...@@ -29,7 +29,7 @@ module Shotengai
# Using validates_uniqueness_of do not work if the order of Hash is diff # Using validates_uniqueness_of do not work if the order of Hash is diff
validate :uniq_spec validate :uniq_spec
custom_hash_columns :spec, :remark custom_hash_columns :spec, :remark, :info
delegate :title, :detail, :banners, :cover_image, :status, :status_zh, :manager, to: :product delegate :title, :detail, :banners, :cover_image, :status, :status_zh, :manager, to: :product
......
...@@ -36,7 +36,7 @@ module Shotengai ...@@ -36,7 +36,7 @@ module Shotengai
validate :check_remark validate :check_remark
validates :count, numericality: { only_integer: true, greater_than: 0 } validates :count, numericality: { only_integer: true, greater_than: 0 }
custom_hash_columns :spec, :remark custom_hash_columns :spec, :info, :remark
validate :cannot_edit, if: :order_was_paid validate :cannot_edit, if: :order_was_paid
before_destroy :cannot_edit, if: :order_was_paid before_destroy :cannot_edit, if: :order_was_paid
...@@ -129,6 +129,7 @@ module Shotengai ...@@ -129,6 +129,7 @@ module Shotengai
original_price: series.original_price, original_price: series.original_price,
price: series.price, price: series.price,
spec: series.spec, spec: series.spec,
info: series.info,
banners: series.banners, banners: series.banners,
cover_image: series.cover_image, cover_image: series.cover_image,
detail: series.detail, detail: series.detail,
......
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