我有一个允许用户关注/取消关注其他用户的应用程序。此关系存储在relationships
具有字段id
、follower_id
和的表中followed_id
。当我调用该方法取消关注用户时,它会破坏关系,但随后会尝试使用已破坏的关系而不是 usersdestroy
重定向回关注的用户。这是/曾经存储在关系表的字段中。我不知道如何在rails中解决这个问题。id
id
id
followed_id
这是关系控制器
class RelationshipsController < ApplicationController
def create
@relationship = Relationship.new
@relationship.followed_id = params[:followed_id]
@relationship.follower_id = current_user.id
if @relationship.save
redirect_to User.find params[:followed_id]
else
flash[:error] = "Couldn't Follow"
redirect_to root_url
end
end
def destroy
@relationship = Relationship.find(params[:id])
@relationship.destroy
redirect_to user_path params[:id]
end
end