Rails [已解决] Rails 嵌套属性问题

loyalpartner · March 02, 2015 · Last by loyalpartner replied at March 02, 2015 · 2096 hits

Model

class Product
  include Mongoid::Document
  field :name, type: String
  field :description, type: String
  ...
  embeds_one :pricing
end

class Pricing
  include Mongoid::Document

  field :retail, type: Integer, default: 0
  field :sale, type: Integer, default: 0

  embedded_in :product
end

现在我要添加一条 Product,提交的数据包含 Pricing,这时候健壮参数要怎么写呢?

我是这么写的,可是不对 - -

params.require(:product).permit(
  :slug, :sku, :name, :description,
  :total_reviews, :average_review, :main_cat_id, 
  :pricing_sale, :pricing_review
  )

已解决:

params.require(:product).permit(
  :slug, :sku, :name, :description,
  :total_reviews, :average_review, :main_cat_id, 
  pricing: [ :sale, :retail ]
  )
You need to Sign in before reply, if you don't have an account, please Sign up first.