title: Adding friends in ruby on rails
body: <p>i am following this post for adding users as friends in ruby on rails</p>
  
  <p><a href="http://asciicasts.com/episodes/163-self-referential-association" rel="nofollow">http://asciicasts.com/episodes/163-self-referential-association</a></p>
  
  <p>I am able to add users as friends via rails console but not via the actual page...this is my controller code</p>
  
  <pre><code>class FriendshipsController &lt; ApplicationController
    def new
    end
  
    def create  
      @friendship = current_user.friendships.build(:friend_id =&gt; params[:friend_id])  
      if @friendship.save  
        flash[:notice] = "Added friend."  
        redirect_to phones_index_path  
      else  
        flash[:notice] = "Unable to add friend."  
        redirect_to phones_index_path
      end  
    end 
  
    def show
    end
  end
  </code></pre>
  
  <p>Model:
  User:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    # Include default devise modules. Others available are:
    # :token_authenticatable, :confirmable,
    # :lockable, :timeoutable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :trackable, :validatable
  has_many :contacts
  has_many :phones
  has_many :friendships
  has_many :friends, :through =&gt; :friendships
  has_many :inverse_friendships, :class_name =&gt; "Friendship", :foreign_key =&gt; "friend_id"  
  has_many :inverse_friends, :through =&gt; :inverse_friendships, :source =&gt; :user  
    # Setup accessible (or protected) attributes for your model
    attr_accessible :email, :password, :password_confirmation, :remember_me, :user_id
    # attr_accessible :title, :body
  end
  </code></pre>
  
  <p>friends:</p>
  
  <pre><code>class Friendship &lt; ActiveRecord::Base
    attr_accessible :friend_id, :user_id
    belongs_to :user
    belongs_to :friend, :class_name =&gt; 'User'
  end
  </code></pre>
  
  <p>view:</p>
  
  <pre><code>&lt;h1&gt;Phones#index&lt;/h1&gt;
  &lt;center&gt;Users in the system&lt;center&gt;&lt;br/&gt;
  &lt;p&gt;&lt;% @phones.each do |variable|%&gt;
      &lt;% if @phn.email!= variable.email %&gt;
      &lt;br/&gt;&lt;%= variable.email %&gt; &amp;nbsp; &lt;%= link_to 'Add as Friend' , friendships_path(:friend_id =&gt; @user), :method =&gt; :post %&gt;
      &lt;%end%&gt;
      &lt;%end%&gt;
  &lt;p&gt;friends&lt;/p&gt;
  &lt;% for user in current_user.friends %&gt;
  &lt;p&gt;&lt;%= user.email %&gt;&lt;/p&gt;
  &lt;%end%&gt;
  </code></pre>
  
  <p>my view is working correctly .. if i add friends via console and commit it, it displays in the view..
  where did i go wrong here??</p>