OmniAuth 未添加到数据库
所以我试图将omniauth构建到我的webpapp中:
从SessionsController调用Omni-Auth
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
cookies.permanent.signed[:user_id] = user.id
redirect_to assignment_path
end
end
然后将用户添加到用户模型中的数据库
class User < ActiveRecord::Base
def self.create_with_omniauth(auth)
create! do |user|
user.name = auth["user_info"]["name"]
user.picture = auth["user_info"]["profile_image_url"]
user.screen_name = auth["user_info"]["screen_name"]
user.provider = auth["provider"]
user.uid = auth["uid"]
end
end
end
名称,uid和提供者添加到数据库但不幸的是图片和screen_name没有得到添加到数据库。
有人可以帮忙吗?
So I am trying to build omniauth into my webpapp:
Omni-Auth gets called from SessionsController
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
cookies.permanent.signed[:user_id] = user.id
redirect_to assignment_path
end
end
And then users are added to the DB in the User model
class User < ActiveRecord::Base
def self.create_with_omniauth(auth)
create! do |user|
user.name = auth["user_info"]["name"]
user.picture = auth["user_info"]["profile_image_url"]
user.screen_name = auth["user_info"]["screen_name"]
user.provider = auth["provider"]
user.uid = auth["uid"]
end
end
end
The name, uid and provider get added to the DB but unfortunately the picture and screen_name do not get added to the DB.
Can any one help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题解决了。
我使用错误的参数访问哈希。
Problem solved.
I was accessing the hash using the wrong parameters.