0

私はこのリンクをたどって友情システムを構築しようとしています:ソーシャルネットワーキングアプリケーションのRails 3に友情モデルを実装する方法は?。ただし、コードは非常に古くなっているようで、変更する可能性があります。atmで実行しようとしているのは、単に関係を作成することですが、これは機能しないようです。

だからここに私の作成

  #Send a friendship request
  def create
    Friendship.request(@customer, @friend)
    redirect_to friendships_path
  end

これは、技術的には、前の投稿ですでに実装したモデルにあるメソッド要求を呼び出します。

  def self.request(customer, friend)
    unless customer == friend or Friendship.exists?(customer, friend)
      transaction do
        create(:customer => customer, :friend => friend, :status => 'pending')
        create(:customer => friend, :friend => customer, :status => 'requested')
      end
    end
  end

そして私もこれらをモデルに追加しました

attr_accessible :status, :customer_id, :friend_id, :customer, :friend

しかし、友情は生まれません。どうしてですか?私は関係が続いていると呼びます

<%= link_to "Add friend", friendships_path(:friend_id => customer), :method => :post %>
4

1 に答える 1

0

@customerと@friendを分離する必要があります。リンクでは、:friend_idを顧客に設定しており、@customerIDを設定することはありません。

これを試して:

def create
  @customer = current_account
  @friend = Account.find(params[:friend_id])
  Friendship.request(@customer, @friend)
  redirect
end

link_toには、次のものが必要です。

<%= link_to "Add Friend", friendships_path(:friend_id => friend),: method => :post %>
于 2012-08-27T19:24:56.340 に答える