私はこのリンクをたどって友情システムを構築しようとしています:ソーシャルネットワーキングアプリケーションの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 %>