Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redirect RAILS 4在编辑和更新后,帖子的id作为用户传递,为什么?_Redirect_Ruby On Rails 4_Updates - Fatal编程技术网

Redirect RAILS 4在编辑和更新后,帖子的id作为用户传递,为什么?

Redirect RAILS 4在编辑和更新后,帖子的id作为用户传递,为什么?,redirect,ruby-on-rails-4,updates,Redirect,Ruby On Rails 4,Updates,我有一个有很多帖子的用户模型,但当用户更新帖子时,我几乎没有问题。当第一个用户(用户id:1)更新帖子(比如帖子id:13)时,在重定向时,页面尝试重定向到用户id:13。有人知道这是为什么吗?这是我的代码行。。提前谢谢 posts\u controller.rb . . 用户\u controller.rb . . 您正在重定向到用户路径。您想重定向到post_路径。除非您想要的是指向用户路径。然后,您需要将用户id传递给它:user\u path(current\u user.id)

我有一个有很多帖子的用户模型,但当用户更新帖子时,我几乎没有问题。当第一个用户(用户id:1)更新帖子(比如帖子id:13)时,在重定向时,页面尝试重定向到用户id:13。有人知道这是为什么吗?这是我的代码行。。提前谢谢

posts\u controller.rb . .

用户\u controller.rb . .

您正在重定向到用户路径。您想重定向到post_路径。除非您想要的是指向用户路径。然后,您需要将用户id传递给它:
user\u path(current\u user.id)

  def update
    @post = current_user.posts.find(params[:id])
    if @post.update_attributes(post_params)
      redirect_to user_path, notice: "Successfully updated!"
    else
      render action: "edit"
    end
  end
  def show
    @user = User.find(params[:id])
    @posts = @user.posts.paginate(page: params[:page])
  end
redirect_to **user_path**, notice: "Successfully updated!"