0
我有一个评论资源嵌套在帖子资源。
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(params[:comment])
@comment.ip = request.remote_ip
if @comment.save
redirect_to post_path(@post, notice: "Comment was successfully created")
else
flash[:alert] = "Comment could not be created"
render 'posts/show'
end
end
这一切工作不够好,但我有一个唠叨项目时与评论形式的职位/显示页面重新呈现,它表明,未通过验证的内联注释。我想知道正确的方法来做到这一点,短视图层中的一些逻辑,不显示未保存的评论。