1

我有一个像这样在评论控制器中创建的动作

def create
    @comment = Comment.new(comment_params)
    @comment.user = current_user
    @comment.post = @post
    if @comment.save
      flash[:notice] = 'Comment was successfully created!'
      redirect_to root_path
    else
      flash[:alert] = "Cant add comment.\n#{@comment.errors.full_messages.join(',')}"
      redirect_to root_path
    end
  end

此操作的请求来自索引页面上的表单。现在我想在显示页面上使用相同的表单。问题:如何制作这样的条件:

 if @comment.save
   if something
    redirect_to show_path
   else
    redirect_to root_path
   end
 else
  if something
    redirect_to show_path
  else
    redirect_to root_path
  end
 end
4

0 回答 0