![](/img/trans.png)
[英]Rails + Authlogic @current_user problem - “Show” method no longer works
[英]Authlogic and Rails 4 - “current_user is undefined method”
我已经在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
任何想法表示赞赏。 谢谢! 凯蒂
Authlogic正在为我的Rails 4应用程序工作。 current_user工作正常。 您可能想再试一次。
Authlogic现在正在工作。 如果有问题,请在您的gemfile中提供以下内容:
gem'authlogic',github:'binarylogic / authlogic',参考号:'e4b2990d6282f3f7b50249b4f639631aef68b939'
@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 logger的代码):
F, [2014-03-04T07:25:09.640105 #28602] FATAL -- : NameError (uninitialized constant SCrypt):
app/controllers/user_sessions_controller.rb:15:in `create'
再次感谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.