我正在使用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
答案 0 :(得分:1)
试试这个:
user.email = auth.info.email unless auth.info.email.blank?
这将检查nil和空值的auth哈希值。