我已经在我的 Rails 4 应用程序中实现了 Authlogic。我可以连接到我的 LDAP 服务器并使用我的 AD 用户名和密码进行身份验证。但是,我不能在应用程序的任何地方调用“current_user”。
例如,当我打电话 Welcome, <%= current_user.first_name %>
我得到: undefined method 'first_name' for nil:NilClass
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
helper :all
protect_from_forgery with: :exception
helper_method :current_user_session, :current_user
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user
end
end
任何想法表示赞赏。谢谢!凯蒂