[英]Facebook-omniauth & associations: how to associate friends with a user
我正在使用Facebook-Omniauth gem將人們連接到我的應用程序。 我可以看到新用戶登錄后,它在數據庫中創建了新用戶記錄。 我的應用程序應該將用戶連接到他們的朋友和他們的事件...但是它只是將用戶連接到所有朋友(人)和數據庫中的所有事件。
在User.rb中:
has_many :people
has_many :people,
:through => :friends
In Person.rb:
has_many :users,
:through => :friends
在Friend.rb中:
belongs_to :person
belongs_to :users
通過Omniauth進行身份驗證后,我遍歷了用戶擁有的所有朋友,並嘗試將其添加為用戶的朋友,如下所示:
self.people << @new_person
但是ActiveRecord大喊:
[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>
我想念什么?
你有:
has_many :friends
在您的模型中?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.