我正在尝试在我的应用中过滤用户搜索的结果,以仅显示不是朋友的用户。我的朋友表有 3 列;f1(发送请求的人的用户名),f2(收到请求的朋友的用户名)和确认(真或假的布尔值)。如您所见,@usersfiltered 是搜索的结果。然后建立当前用户好友的定义。然后我试图从搜索结果中删除朋友。这似乎不起作用,但应该非常简单。我试过删除(不好)和销毁。
def index
#THIS IS THE SEARCH RESULT
@usersfiltered = User.where("first_name LIKE?", "%#{params[:first_name]}%" )
#THIS IS DEFINING ROWS ON THE FRIEND TABLE THAT BELONG TO CURRENT USER
@confirmedfriends = Friend.where(:confirmed => true)
friendsapproved = @confirmedfriends.where(:f2 => current_user.id)
friendsrequestedapproved = @confirmedfriends.where(:f1 => current_user.id)
#GOING THROUGH SEARCH RESULTS
@usersfiltered.each do |usersfiltered|
if friendsapproved.present?
friendsapproved.each do |fa|
if usersfiltered.id == fa.f1
#NEED TO REMOVE THIS FROM RESULTS HERE SOMEHOW
usersfiltered.remove
end
end
end
#SAME LOGIC
if friendsrequestedapproved.present?
friendsrequestedapproved.each do |fra|
if usersfiltered.id == fra.f2
usersfiltered.remove
end
end
end
end
结尾