我有两个模型正在处理事件和报告。报告并嵌入事件中。我在为特定事件创建新报告时遇到问题。
我认为我的报告控制器新操作需要看起来像这样:
@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?
}
提前致谢。