我有两个模型,我正在使用事件和报告。报告并嵌入到事件中。我无法为特定活动创建新报告。Mongoid在父内创建新的嵌入式文档
我觉得我的遥控器新的行动必须是这个样子:
@event = Event.find(params[:eventid])
@report = @event.report.build
在我的事件模型中,我有以下设置:
embeds_one :report
accepts_nested_attributes_for :report
当我尝试保存我收到以下错误:
Mongoid::Errors::NoParent
这是我的报告模型
class Report
include Mongoid::Document
include Mongoid::Timestamps
field :test, type: String
embedded_in :event, :inverse_of => :report
embeds_many :report_details
accepts_nested_attributes_for :report_details,
:allow_destroy => true,
:reject_if => proc { |attributes|
attributes['name'].blank? && attributes['_destroy'].blank?
}
这里是我的事件模型
class Event
include Mongoid::Document
include Mongoid::Timestamps
embeds_one :report
accepts_nested_attributes_for :report,
:allow_destroy => true,
:reject_if => proc { |attributes|
attributes['name'].blank? && attributes['_destroy'].blank?
}
在此先感谢。
请给你的模型结构 – abhas