1

我有模型post.rb

class Post
 include Mongoid::Document
 attr_accessible :content, :original_post
end

posts_controller.rb中创建操作:

def create
 @post = Post.new(params[:post])
 @post.original_post = @post
 @post.save
end

我想知道这篇文章是原创的,因为我会复制这篇文章,并且我会有更多具有相同功能的帖子。

但是,当我尝试创建帖子时,出现错误:

BSON::InvalidDocument(不能将 Post 类的对象序列化为 BSON。):

4

1 回答 1

0

您是否尝试过序列化空 Post,例如:

@post = Post.new(params[:post])
@post.save

可能问题在于它@post包含自身作为变量。并且不能序列化为 json (bson)。

于 2012-02-05T21:58:36.510 回答