私は基本的なソーシャルネットワークを持っています。ユーザーの配列を返す friends メソッドを作成しようとしています。一部user :idsは:user_id属性内にあり、一部は属性内にあり:friend_idます。を返したくないcurrent_user.id。:name、:idおよび:uid属性のみを返したい。ここからどこへ行けばいいのかわからない。
質問に情報が不足している場合は教えてください。
ありがとうございました!
class User < ActiveRecord::Base
has_many :friendships, :conditions => {:accepted => true}
has_many :inverse_friendships, :class_name => "Friendship", :foreign_key => "friend_id", :conditions => {:accepted => true}
attr_accessible :name, :oauth_expires_at, :oauth_token, :provider, :uid
def friends
friendships.preload(:friend) + inverse_friendships.preload(:user)
end
end
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, :class_name => "User"
attr_accessible :accepted, :friend_id, :user_id, :friend
end