0

我正在使用 twitter 和 facebook 连接到一个网站。当提供者是 Facebook 时,我想将用户电子邮件添加到数据库字段,而它的 twitter 应该没有电子邮件。下面的代码使我的服务器超时。

 def self.from_omniauth(auth)
    where(provider: auth['provider'], uid: auth['uid']).first_or_create do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.profile_data = auth.info
      user.email = auth.info.email unless user.email.nil?

      user.token = auth['credentials']['token'] unless auth['credentials'].nil?
      user.secret = auth['credentials']['secret'] unless auth['credentials'].nil?
    end
  end

我也试过

def self.from_omniauth(auth)
    where(provider: auth['provider'], uid: auth['uid']).first_or_create do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.profile_data = auth.info
      user.email = auth.info.email unless auth.info.email?

      user.token = auth['credentials']['token'] unless auth['credentials'].nil?
      user.secret = auth['credentials']['secret'] unless auth['credentials'].nil?
    end
  end

Heroku 上的错误:

2012-08-21T23:30:07+00:00 heroku[router]: Error H12 (Request timeout) -> GET www.myapp.com/ dyno=web.1 queue= wait= service=30000ms status=503 bytes=0
4

1 回答 1

1

试试这个:

user.email = auth.info.email unless auth.info.email.blank?

这将检查 nil 和空值的 auth 哈希。

于 2012-08-21T13:20:26.617 回答