Katie M
Katie M

Reputation: 1131

Authlogic and Rails 4 - "current_user is undefined method"

I've implemented Authlogic in my Rails 4 app. I can connect to my LDAP server and authenticate with my AD username and password. But, I cannot call "current_user" anywhere in the app.

For instance, when I call Welcome, <%= current_user.first_name %>

I get: 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

Any ideas are appreciated. Thanks! Katie

Upvotes: 0

Views: 3084

Answers (4)

Adrien Lamothe
Adrien Lamothe

Reputation: 1489

@rhuppert, that particular authlogic commit really saved my bacon, thank you for sharing that information. Turns out the newer Authlogic versions, 3.3.0 and 3.4.0, no longer work with one of my Rails 4.0.x apps, but when I use the version you mention (gem 'authlogic', github: 'binarylogic/authlogic', ref: 'e4b2990d6282f3f7b50249b4f639631aef68b939') it works with Rails 4.0.x. The error I was getting with both Authlogic 3.4.0 and 3.8.0 was (line from Rails logger):

F, [2014-03-04T07:25:09.640105 #28602] FATAL -- : NameError (uninitialized constant SCrypt):
  app/controllers/user_sessions_controller.rb:15:in `create'

Thanks again!

Upvotes: 0

rhuppert
rhuppert

Reputation: 83

Authlogic is now working. if there are issues, provide the following in your gemfile:

gem 'authlogic', github: 'binarylogic/authlogic', ref: 'e4b2990d6282f3f7b50249b4f639631aef68b939'

Upvotes: 2

Adrien Lamothe
Adrien Lamothe

Reputation: 1489

Authlogic is working for my Rails 4 app. current_user works just fine. You may want to try it again.

Upvotes: 3

Jesse Wolgamott
Jesse Wolgamott

Reputation: 40277

Authlogic, as of today, is not ready for Rails 4:

http://ready4rails4.net/

Name: authlogic
Status: not ready
Notes: pull request

Upvotes: 0

Related Questions