NoMethodError(未定义的方法“持续存在?”对于 true:TrueClass)

NoMethodError(undefined method `persisted?' for true:TrueClass)

我正在实施一个 rails 网络应用程序,在此应用程序中,我使用 Devise+ Omniauth 进行身份验证。在我的 Devise 模型中,我还使用了可确认块。

现在,当我尝试通过 omniauth 为 facebook 或 google 实施社交登录时,我收到以下错误

  NoMethodError at /customer/auth/google_oauth2/callback
  undefined method `persisted?' for true:TrueClass

这是我的 omniauth_callbacks 控制器的代码

    class OmniauthCallbacksController < Devise::OmniauthCallbacksController

    skip_before_filter :authenticate_user!
    def all
        p env["omniauth.auth"]
        user = User.from_omniauth(env["omniauth.auth"], current_user)
        if user.persisted?
            flash[:notice] = "You are in..!!! Go to edit profile to see the status for the accounts"
            sign_in_and_redirect(user)
        else
            session["devise.user_attributes"] = user.attributes
            redirect_to new_user_registration_url
        end
    end

      def failure      
        super
      end


    alias_method :facebook, :all
    alias_method :google_oauth2, :all
end

这是我的用户模型的代码片段

class 用户 < ActiveRecord::Base

devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, :validatable,:confirmable,:token_authenticatable

def self.from_omniauth(auth, current_user)    
    authorization = Authorization.where(:provider => auth.provider, 
                    :uid => auth.uid.to_s, 
                    :token => auth.credentials.token, 
                    :secret => auth.credentials.secret).first_or_initialize

    if authorization.user.blank?
        user = current_user || User.where('email = ?', auth["info"]["email"]).first        
        if user.blank?       
          user = User.new
          user.name = auth.info.name
          user.email= auth.info.email
          if auth.provider == "twitter" 
            user.save(:validate => false) 
          else
            user.skip_confirmation!
            user.save(:validate => false)
          end
        end
        authorization.username = auth.info.nickname
        authorization.user_id = user.id
        authorization.save
    end
    authorization.user
end

结束

我的用户模型有很多授权模型(创建用于处理来自多个提供商的帐户)

class Authorization < ActiveRecord::Base
    belongs_to :user

    after_create :fetch_details



    def fetch_details
        self.send("fetch_details_from_#{self.provider.downcase}")
    end


    def fetch_details_from_facebook
        graph = Koala::Facebook::API.new(self.token)
        facebook_data = graph.get_object("me")
        self.username = facebook_data['username']
        self.save
    end
 end

任何人都可以帮助我找出为什么我得到这个 未定义的方法“持续存在?” true:TrueClass

错误?

current_user 助手在 omniauth 行中起什么作用?我假设它正在与 omniauth 环境变量产生某种冲突。

尝试更改:

user = User.from_omniauth(env["omniauth.auth"], current_user)

至:

user = User.from_omniauth(env["omniauth.auth"])