Вложенный атрибут _destroy с параметрами Mongoid и strong_parameters

Я хочу уничтожить документы из отношения 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?


person Kris Braun    schedule 20.12.2014    source источник


Ответы (1)


Со стороны Rails все оказалось в порядке. Именно во внешнем интерфейсе (AngularJS) запрос отправлял variations, а не variations_attributes.

person Kris Braun    schedule 21.12.2014