My app has the following models: user and watch_list. User has attributes id, name and WatchList has attributes user_id, friend_id.
class WatchList < ActiveRecord::Base
belongs_to :user
has_many :friends, :class_name => "User", :foreign_key => "friend_id"
end
class User < ActiveRecord::Base
has_one :watch_list
has_many :friends, :through => :watch_list
def friends_with(friend_id)
self.friends.each do |f|
if f.id == friend_id
return true
end
end
return false
end
end
For some reason when I use @current_user.friends_with(friend_id) I always get 'true' as a response. Any ideas why this won't work right? (I know @current_user works)
Thanks!