我有一个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销毁?