0
我想呈现相同的视图,但是当它们发布评论失败时显示错误消息。使用错误消息呈现当前视图
Comments.controllers
def create
@project = Project.find(params[:project_id])
@comment = @project.comments.build(comment_params)
@comment.user_id = current_user.id
if @comment.save
flash[:success] = "Comment created!"
redirect_to @project
else
@projectboard_items = []
flash[:danger] = "Sorry! your comment was not created"
render @project #<----- replace this line
end
end
谢谢!
所以是的,不,它是我想要的行为,但我的错误消息不会显示在那里,出于某种原因...他们只显示当我渲染视图,但当我这样做时评论饲料消失 – Eltorero1992