[英]Is it possible to save multiple users using omniauth-facebook rails gem?
I have the following code in user.rb using the Facebook-omniauth gem that logs in a single user: 我使用登录单个用户的Facebook-omniauth gem在user.rb中具有以下代码:
def self.from_omniauth(auth)
where(auth.slice(:provider, :fb_id)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.fb_id = auth.uid
user.name = auth.info.name
user.first_name = auth["info"]["first_name"] unless auth["info"].blank?
user.last_name = auth["info"]["last_name"] unless auth["info"].blank?
user.picture_url = auth.info.image
user.email = auth.info.email
user.oauth_token = auth.credentials.token unless auth["info"].blank?
user.location = auth.info.location unless auth["info"].blank?
user.save!
end
I want to build user accounts for multiple facebook users. 我想建立多个Facebook用户的用户帐户。 When I log its fine but when another person signs in, the app replaces my user instance. 当我登录正常但其他人登录时,该应用将替换我的用户实例。 Is there a way to keep building user accounts from this gem? 有没有办法从这个gem继续建立用户帐户?
Thanks! 谢谢!
The solution was in the second line at: where(auth.slice(:provider, :fb_id))
解决方案在第二行中: where(auth.slice(:provider, :fb_id))
I changed it from :uid to :fb_id to match the facebook id of everything else in all my other tables but after inspecting the auth
hash I realized that :fb_id was not found at all and thus wasn't producing any new Users. 我将其从:uid更改为:fb_id,以匹配我所有其他表中所有其他内容的facebook id,但是在检查auth
哈希后,我意识到:fb_id根本找不到,因此没有产生任何新用户。
I renamed my User fb_id
column back to uid
and it now collects new users properly: 我将User fb_id
列重命名为uid
,现在可以正确收集新用户了:
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.first_name = auth["info"]["first_name"] unless auth["info"].blank?
user.last_name = auth["info"]["last_name"] unless auth["info"].blank?
user.picture_url = auth.info.image.sub("square", "large")
user.email = auth.info.email
user.oauth_token = auth.credentials.token unless auth["info"].blank?
user.location = auth.info.location unless auth["info"].blank?
user.save!
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.