【问题标题】:OmniAuth not getting added to databaseOmniAuth 未添加到数据库中
【发布时间】:2011-02-23 01:43:34
【问题描述】:

所以我正在尝试将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 和提供程序被添加到数据库中,但不幸的是图片和屏幕名称没有被添加到数据库中。

有人可以帮忙吗?

【问题讨论】:

  • 您的迁移中有必要的字段吗?
  • 我解决了这个问题,见下文。

标签: ruby-on-rails ruby ruby-on-rails-3 omniauth


【解决方案1】:

问题解决了。

我使用错误的参数访问哈希。

【讨论】:

  • 以前去过那里。这个小技巧在这些情况下很方便:raise params.to_yaml。或者,对于 OmniAuth:raise request.env["omniauth.auth"].to_yaml
猜你喜欢
  • 1970-01-01
  • 2011-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-24
  • 2016-11-26
  • 1970-01-01
  • 2014-05-30
相关资源
最近更新 更多