我正在尝试为我的网站使用omniauth-twitter,但每当我点击Twitter登录时,我都会收到此错误
undefined method `persisted?' for []
omniauth_callbacks_controller.rb文件......
def twitter
# You need to implement the method below in your model
@user = User.find_for_twitter_oauth(request.env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Twitter"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.twitter_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
User.rb文件......
def self.find_for_twitter_oauth(access_token, signed_in_resource=nil)
data = access_token.extra.raw_info
if user = User.where(:email => data.email)
user
else # Create a user with a stub password.
User.create!(:name => data.name, :email => data.email, :password => Devise.friendly_token[0,20])
end
end
有什么想法吗?
答案 0 :(得分:4)
user = User.where(:email => data.email).first()