无法保存Google个人资料图片

时间:2019-08-18 06:19:55

标签: ruby-on-rails ruby google-oauth2

我正在与Google进行身份验证。我完全可以获取Google身份验证信息,但无法保存个人资料照片。 Carrierwave可以工作,我也可以找到Google图片网址。但是我无法保存...

我遇到了这个错误。

NoMethodError: undefined method `[]' for nil:NilClass
from /Users/xxx/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/carrierwave-2.0.0/lib/carrierwave/downloader/remote_file.rb:28:in `filename_from_header'

apps / models / user.rb

def self.find_for_google_oauth(auth)
  where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
    binding.pry
    user.email = auth.info.email
    user.password = Devise.friendly_token[0,20]
    user.username = auth.info.name
    user.remote_image_url = auth.info.image
    user.confirmed_at = Time.now.utc
  end
end

config / initializers / devise.rb

config.omniauth :google_oauth2,
  Rails.application.credentials.google[:client_id],
  Rails.application.credentials.google[:client_secret],
  skip_jwt: true,
  scope: 'email profile',
  redirect_uri: "#{Rails.application.credentials[Rails.env.to_sym][:host_domain]}/users/auth/google_oauth2/callback"

1 个答案:

答案 0 :(得分:0)

我在版本下降后通过了载波(1.3.1)。