Redirect RAILS 4在编辑和更新后,帖子的id作为用户传递,为什么?
我有一个有很多帖子的用户模型,但当用户更新帖子时,我几乎没有问题。当第一个用户(用户id:1)更新帖子(比如帖子id:13)时,在重定向时,页面尝试重定向到用户id:13。有人知道这是为什么吗?这是我的代码行。。提前谢谢 posts\u controller.rb . . 用户\u controller.rb . . 您正在重定向到用户路径。您想重定向到post_路径。除非您想要的是指向用户路径。然后,您需要将用户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)
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!"