无法将类Post的对象序列化为BSON

时间:2012-02-05 20:53:18

标签: ruby-on-rails mongoid bson

我的模特 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。):

1 个答案:

答案 0 :(得分:0)

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

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

问题可能是@post将自身包含为变量。并且它无法序列化为json(bson)。

相关问题