イベントとレポートで作業しているモデルが2つあります。レポートとイベントに埋め込まれます。特定のイベントの新しいレポートを作成するのに問題があります。
レポートコントローラーの新しいアクションは、次のようになる必要があると思います。
@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?
}
前もって感謝します。