Rails + Omniauth:nil:NilClass的未定义方法“ []”

时间:2019-09-09 22:40:02

标签: ruby-on-rails ruby ruby-on-rails-4 devise

我正在尝试使用Spotify API通过Devise注册用户/但我得到了:

undefined method []'代表nil:NilClass`

在:

pages_controller.rb

@spotify_user = RSpotify::User.new(request.env['omniauth.auth'])

===

这是我的书架:

home.html.erb

<li><%= link_to 'Sign in with Spotify', user_spotify_omniauth_authorize_path %></li>

routes.rb

devise_for :users, :controllers => { :omniauth_callbacks => 'callbacks' }  

callbacks_controller.rb

class CallbacksController <  Devise::OmniauthCallbacksController
  skip_before_action :verify_authenticity_token
  def spotify
    @user = User.from_omniauth(request.env["omniauth.auth"])
    sign_in_and_redirect @user
  end
end

initializers / devise.rb

  RSpotify.authenticate(ENV["SPOTIFY_CLIENT_ID"], ENV["SPOTIFY_CLIENT_SECRET"])
  config.omniauth :spotify, ENV["SPOTIFY_CLIENT_ID"], ENV["SPOTIFY_CLIENT_SECRET"], scope: 'user-read-email playlist-modify-public user-library-read user-library-modify'

0 个答案:

没有答案