I'd like to destroy documents from an embeds_many
relationship using a request attribute.
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
When making a request with _destroy
, I get the error:
Mongoid::Errors::UnknownAttribute -
Problem:
Attempted to set a value for '_destroy' which is not allowed on the model ExperienceVariation.
How can I get nested _destroy
to work?
Everything turned out to be fine on the Rails side. It was in the front-end (AngularJS) that the request was sending variations
rather than variations_attributes
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.