由于这个其他问题,我已经修改了我的范围,所以现在我请求正确的权限,以便我可以将用户的性别和位置保存到数据库。
这是我保存所有信息栏性别和位置的 user.rb 代码。遵循 auth.info.name 等设置的协议后,性别或位置都不会被保存甚至检索。
def self.from_omniauth(auth)
    where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.name = auth.info.name
      user.email = auth.info.email
      user.picture = auth.info.image
      user.gender = auth.info.gender
      user.country = auth.info.locale
      user.oauth_token = auth.credentials.token
      user.oauth_expires_at = Time.at(auth.credentials.expires_at)
      user.save! 
      end
     end
这是我发送的范围
  Rails.application.config.middleware.use OmniAuth::Builder do
  provider :youtube, YOUTUBE_KEY, YOUTUBE_SECRET, { :scope => "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://gdata.youtube.com", access_type: 'offline', approval_prompt: '' }
end
路线
match 'auth/youtube/callback', to: 'sessions#create'
有谁知道保存这两个值的正确方法?