Topic: How to avoid being friends multiple times

Hello , I am trying to create a social network. My problem is that , I can be friends multiple times. I know i need to find a way to find a condition to avoid it but i cant get the correct solution .
my link to add friends is :

  <h1><%= @user.username %> </h1> 
      <%= link_to "Arkadaşlarıma Ekle", friendships_path(:friend_id => @user), :method => :post,class: "btn btn-large btn-primary" %>
  
      </section>

This is my users controller :

class UsersController < ApplicationController
    before_filter :authenticate_user!

  def index
        @users = User.all
  end
  def show
    @user = User.find(params[:id])
    @topics = @user.topics.paginate(page: params[:page])
    @friendship = @user.friendships.build(:friend_id => params[:friend_id])
    @friendships = @user.friendships.all

  end

How can i add a tester for being friends?

Re: How to avoid being friends multiple times

Try something like this:

class UsersController < ApplicationController
    before_filter :authenticate_user!

  def index
        @users = User.all
  end
  def show
    @user = User.find(params[:id])
    @topics = @user.topics.paginate(page: params[:page])
    
    unless @user.friendships.where(:friend_id => params[:friend_id]).exists?
      @friendship = @user.friendships.build(:friend_id => params[:friend_id])
    end

    @friendships = @user.friendships.all

  end