제품을 편집하고 제품 모델에 포함 된 '구성 요소'모델의 행을 삭제할 때 유효성 검사에 실패하면 삭제 된 문서가 다시 편집 페이지에 나타납니다.유효성 검사에 실패한 경우 포함 문서가 제거되지 않음
업데이트 방법 :
# Put /products/:id
def update
@product=Product.find(params[:id])
if(@product.update_attributes(params[:product]))
logger.info @product.attribute.components.inspect
redirect_to product_path , notice:'update complete'
else
logger.info @product.attribute.components.inspect
render_by_type_id(@product.product_type._id,false,mode='edit')
end
end
모델 :
class Product
include Mongoid::Document
include ScopedSearch::Model
embeds_one :attribute ,class_name:"ProductAttribute"
accepts_nested_attributes_for :attribute, :product_items ,:lab_test ,allow_destroy: true
end
class ProductAttribute
include Mongoid::Document
embedded_in :product
embeds_many :components , inverse_of: nil
accepts_nested_attributes_for :components, :allow_destroy => true
end
포함 된 모델 :
class Component
include Mongoid::Document
embedded_in :product_attribute
end
"_destroy"열의 데이터베이스 마이그레이션을 생성했는지 확인 했습니까? –