所以我想在我的webpapp中构建omniauth:
Omni-Auth从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
然后将用户添加到用户模型中的数据库
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不会添加到数据库中。
任何人都可以帮忙吗?
答案 0 :(得分:0)
问题解决了。
我使用错误的参数访问哈希。