我有一个使用 Omni-Auth GitHub gem 的 Rails 应用程序。通过 GitHub 创建和登录用户帐户完美无缺!
这是我的用户模型:
def self.from_omniauth(auth)
find_by_github_uid(auth["uid"]) || create_from_omniauth(auth)
end
def self.create_from_omniauth(auth)
create! do |user|
user.github_uid = auth["uid"]
user.github_token = auth["credentials"]["token"]
user.username = auth["info"]["nickname"]
user.email = auth["info"]["email"]
user.full_name = auth["info"]["name"]
user.gravatar_id = auth["extra"]["raw_info"]["gravatar_id"]
user.blog_url = auth["extra"]["raw_info"]["blog"]
user.company = auth["extra"]["raw_info"]["company"]
user.location = auth["extra"]["raw_info"]["location"]
user.hireable = auth["extra"]["raw_info"]["hireable"]
user.bio = auth["extra"]["raw_info"]["bio"]
end
end
但有时用户会更改他们的简历或公司,或者他们是否想被雇用,所以我不必删除旧帐户,我认为如果在他们更新帐户后及时更新它会很好。
执行此操作的最佳做法是什么?如何使用现有的 OmniAuth 代码更新用户信息?