我已经在我的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
任何想法都表示赞赏。谢谢! 凯蒂
答案 0 :(得分:3)
Authlogic正在为我的Rails 4应用程序工作。 current_user工作正常。你可能想再试一次。
答案 1 :(得分:2)
Authlogic现在正在运作。如果有问题,请在gemfile中提供以下内容:
gem'authlogic',github:'binarylogic / authlogic',ref:'e4b2990d6282f3f7b50249b4f639631aef68b939'
答案 2 :(得分:0)
答案 3 :(得分:0)
@rhuppert,那个特定的authlogic提交真的保存了我的培根,谢谢你分享这些信息。原来的新版Authlogic版本3.3.0和3.4.0不再适用于我的一个Rails 4.0.x应用程序,但是当我使用你提到的版本时( gem'authlogic',github:'binarylogic / authlogic',ref:'e4b2990d6282f3f7b50249b4f639631aef68b939')它适用于Rails 4.0.x.我在Authlogic 3.4.0和3.8.0中遇到的错误是(来自Rails记录器):
F, [2014-03-04T07:25:09.640105 #28602] FATAL -- : NameError (uninitialized constant SCrypt):
app/controllers/user_sessions_controller.rb:15:in `create'
再次感谢!