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
這一切工作不夠好,但我有一個嘮叨項目時與評論形式的職位/顯示頁面重新呈現,它表明,未通過驗證的內聯註釋。我想知道正確的方法來做到這一點,短視圖層中的一些邏輯,不顯示未保存的評論。