When deleting a user from friends, it gives an error:
ActiveRecord::RecordNotFoundinFriendshipsController#destroy
Couldn't findFriendshipwith'id'=2[WHERE "friendships"."user_id" = ?]
friendships controller:
class FriendshipsController < ApplicationController def create @friendship = current_user.friendships.build(:friend_id => params[:friend_id]) if @friendship.save flash[:success] = "Пользователь добавлен в друзья." redirect_to root_path else flash[:alert] = "Невозможно добавить в друзья." redirect_to root_path end end def destroy @friendship = current_user.friendships.find(params[:id]) @friendship.destroy flash[:notice] = "Пользователь удален из друзей." redirect_to current_user end end Controller users :
def my_friends @friendships = current_user.friends end Presentation file in the users controller:
<% @friendships.each do |friend| %> <%= friend.name %> <%= link_to "Профиль пользователя", user_path(friend), class: "button" %> <%= link_to "Удалить из друзей", friendship_path(friend), method: :delete %> <% end %>