0
我試圖保存蒙戈::文獻中嵌入另一個。我的課:NoMethodError(未定義的方法),用於嵌入對象
class Block
include Mongoid::Document
field :name, type: String
field :text, type: String
embeds_many :replies
end
其他類:
class Reply
include Mongoid::Document
field :content_type, type: String
field :title, type: String
field :payload, type: String
embedded_in :block
end
,創造方法控制器:
def create
@block = Block.where(:name => block_params[:name])
@quick_reply = Reply.new(title: params[:block][:quick_replies][:title], payload: params[:block][:quick_replies][:payload])
@block.replies.push(@quick_reply)
@block.name = params[:block][:name]
@block.text = params[:block][:text]
if (@block.save)
respond_to do |format|
format.html {render :template => "block/text/edit"}
end
end
end
我得到這個錯誤:
undefined method `replies' for #<Mongoid::Criteria:0x71cf550>
我想了解爲什麼以及如何解決問題。謝謝。