【发布时间】:2017-04-11 13:57:17
【问题描述】:
我正在尝试保存一个嵌入另一个的 Mongo::Document。我的课:
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>
我想了解为什么以及如何解决该问题。谢谢。
【问题讨论】:
标签: ruby-on-rails ruby mongodb mongoid