在Rails中删除第二级accepts_nested_attributes_for对象

时间:2019-02-27 19:39:31

标签: ruby-on-rails

我有一个Rails 3.2应用程序,并具有以下模型,其中我们有两个级别的accept_nested_attributes_for

class AdSource < ActiveRecord::Base
  has_many :prices, dependent: :destroy
  accepts_nested_attributes_for :prices, allow_destroy: true
  attr_accessible :price_attributess
end

class Price < ActiveRecord::Base
  belongs_to :ad_source

  has_many :price_attributes, dependent: :destroy
  accepts_nested_attributes_for :price_attributes, allow_destroy: true
  attr_accessible :price_attributes_attributes
end

class PriceAttribute < ActiveRecord::Base
  belongs_to :price
end

当我对以下内容进行http放置时,

{"ad_source"=>{"name"=>"blue is cool",  "cpm"=>"2", "id"=>"210", "price_attributes"=>[{"name" => "my something", "id"=>"88", "_destroy"=>"1", "price_attributes_attributes"=>[{"id"=>"88", "network_attribute_value"=>"i am here"}]}]},
 "id"=>"210",
}

它使用_destroy: 1删除价格,但允许关联的price_attributes徘徊。这似乎有点bug。我是否希望同时发送两个对象的_destroy: 1?还是有办法告诉Rails销毁?

0 个答案:

没有答案