Ruby on rails NoMethodError(未定义的方法'persistend?';表示true:TrueClass)
我正在实现一个rails Web应用程序,在这个应用程序中,我使用Desive+Omniauth进行身份验证。在我的设计模型中,我也使用可确认块 现在,当我尝试通过omniauth为facebook或google实现社交登录时,我得到了以下错误Ruby on rails NoMethodError(未定义的方法'persistend?';表示true:TrueClass),ruby-on-rails,devise,omniauth,Ruby On Rails,Devise,Omniauth,我正在实现一个rails Web应用程序,在这个应用程序中,我使用Desive+Omniauth进行身份验证。在我的设计模型中,我也使用可确认块 现在,当我尝试通过omniauth为facebook或google实现社交登录时,我得到了以下错误 NoMethodError at /customer/auth/google_oauth2/callback undefined method `persisted?' for true:TrueClass 下面是我的omniauth\u回调控
NoMethodError at /customer/auth/google_oauth2/callback
undefined method `persisted?' for true:TrueClass
下面是我的omniauth\u回调控制器的代码
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
结束
我的用户模型有许多授权模型(创建用于处理来自多个提供商的帐户)
类授权
有人能帮我找到为什么我会得到这个吗
true:TrueClass的未定义方法“持久化”
错误?当前用户在omniauth行中扮演什么角色?我假设它与omniauth环境变量产生某种冲突 尝试更改:
user = User.from_omniauth(env["omniauth.auth"], current_user)
致:
这样做是给了错误数量的参数(1代表2)错误转到您的用户模型,看看.from_omniauth方法是如何定义的,还是使用Desive处理的?是的,从用户模型中删除当前_用户参数完成了任务。。谢谢
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
user = User.from_omniauth(env["omniauth.auth"], current_user)
user = User.from_omniauth(env["omniauth.auth"])