gpt4 book ai didi

ruby-on-rails - Omniauth-facebook 未定义方法 `slice' 为 nil :NilClass. SessionsController#create 中的 NoMethodError

转载 作者:太空宇宙 更新时间:2023-11-03 16:33:15 26 4
gpt4 key购买 nike

我关注了this tutorial准确地说,但我收到了这个错误:

NoMethodError in SessionsController#create
undefined method `slice' for nil:NilClass
Rails.root: /Users/raybesiga/Documents/Sites/foodie
Application Trace | Framework Trace | Full Trace
app/models/user.rb:29:in from_omniauth'
app/controllers/sessions_controller.rb:3:increate'

但是我的 user.rb 文件如下:

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :provider, :uid
validates_presence_of :name
validates_uniqueness_of :name, :email, :case_sensitive => false
# attr_accessible :title, :body

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.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
end

我的sessions_controller.rb文件如下:

class SessionsController < ApplicationController
def create
user = User.from_omniauth(env["ominauth.auth"])
# session[:user_id] = user.user_id
session[:user_id] = user.id
redirect_to root_url
end

def destroy
session[:user_id] = nil
redirect_to root_url
end
end

知道为什么会出现此错误吗?

最佳答案

您在 session Controller 中拼写了 env['omniauth.auth'] 错误。你把 env['ominauth.auth']

关于ruby-on-rails - Omniauth-facebook 未定义方法 `slice' 为 nil :NilClass. SessionsController#create 中的 NoMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12162174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com