【发布时间】:2016-02-28 12:06:31
【问题描述】:
我有两种类型的节点“发布”和“评论”,我正在使用 ruby 的 ActiveNode 来创建节点和关系。以下是我的帖子和评论模型:
class Comment
include Neo4j::ActiveNode
property :body, type: String
has_one :out, :post, type: :comments_on
end
class Post
include Neo4j::ActiveNode
property :title, type: String
property :body, type: String
has_many :in, :comments, origin: :post
end
当我在特定帖子上创建评论时,会创建关系,但会创建两次。我无法找到为什么它被创建了两次。
这里分享代码创建评论类
def create
@comment = Comment.new(comment_params)
respond_to do |format|
if @comment.save
format.html { redirect_to @comment, notice: 'Comment was successfully created.' }
format.json { render :show, status: :created, location: @comment }
else
format.html { render :new }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end
【问题讨论】:
-
你能分享你用来创建评论的代码吗?另外,如果对您更好,欢迎您加入我们的聊天室:gitter.im/neo4jrb/neo4j
-
我分享了创建评论的代码,请帮助我。
-
你能输出
comment_params.inspect并分享吗? -
你能解释一下吗?我没听懂。
-
代码并没有告诉我太多。传递给
Comment.new的comment_params变量可能具有相关的详细信息。您能否在create方法的开头添加puts comment_params.inspect,然后将输出复制/粘贴到您的问题中?
标签: ruby-on-rails ruby neo4j