我正在为twitter推行omniauth,并且遇到错误“找不到用户有'id'= true”错误指向应用程序控制器current_user
方法。 Heere是我current_user
方法:找不到'id'= true的用户Omniauth - rails 4
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
helper_method :current_user
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
end
,这里是我的User
型号:
class User < ActiveRecord::Base
def self.find_or_create_by_auth(auth_data)
user = where(provider: auth_data[:provider], uid: auth_data[:uid]).first_or_create
user.update(name: auth_data[:info][:name])
end
end
终于SessionController
低于:
class SessionsController < ApplicationController
def create
@user = User.find_or_create_by_auth(request.env["omniauth.auth"])
session[:user_id] = @user
redirect_to products_path, notice: "logged in as "
end
def destroy
session[:user_id] = nil
redirect_to root_path, notice: "Goodbye!!"
end
end
当我试图登录错误持久性有机污染物我无法通过登录来加载我的索引页面。