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>
我想了解为什么以及如何解决问题。谢谢。