我想使用请求属性销毁embeds_many
关系中的文档。
class Experience
include Mongoid::Document
embeds_many :variations, class_name: 'ExperienceVariation'
accepts_nested_attributes_for :variations, allow_destroy: true
end
class ExperiencesController < ApplicationController
def update
if @experience.update_attributes(experience_params)
show
else
render json: @experience.andand.errors, status: :unprocessable_entity
end
end
def experience_params
params.require(:experience).permit(
...
variations: [
:id, :delete, ...
]
)
end
end
在使用_destroy
发出请求时,出现错误:
Mongoid::Errors::UnknownAttribute -
Problem:
Attempted to set a value for '_destroy' which is not allowed on the model ExperienceVariation.
如何让嵌套_destroy
工作?
答案 0 :(得分:0)
Rails方面的一切都很好。请求发送variations
而不是variations_attributes
的是前端(AngularJS)。