简体   繁体   中英

Facebook-omniauth & associations: how to associate friends with a user

I'm using the Facebook-Omniauth gem to connect people to my app. I can see when a new user logs in, it creates a new user record in my database. My app is supposed to connect users to their friends and their events...but it simply connects users to all friends(people) and all events in the database.

In User.rb:

  has_many :people
  has_many :people, 
    :through => :friends 

In Person.rb:

has_many :users, 
    :through => :friends

In Friend.rb:

belongs_to :person
belongs_to :users 

After authenticating via Omniauth I loop through all the friends a user has and try to add them as the user's friend like so:

self.people << @new_person

But ActiveRecord yells back the following:

[3] pry(#<User>)> self.people << @new_person
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :friends in model User

[4] pry(#<User>)> self.friends << @new_person
NoMethodError: undefined method `friends' for #<User:0x007f9b816850f0>

What am I missing?

Do you have:

 has_many :friends

In your models?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM