我的模特 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。):
答案 0 :(得分:0)
您是否尝试过序列化空帖子,例如:
@post = Post.new(params[:post])
@post.save
问题可能是@post
将自身包含为变量。并且它无法序列化为json(bson)。