class Current < ActiveSupport::CurrentAttributes
attribute :user
end
application controller:
class ApplicationController < ActionController::Base
before_action :authenticate
private
def authenticate
if authenticated_user = User.find_by(auth_token: cookies.encrypted[:auth_token])
Current.user = authenticated_user
// printing Current.user here shows it correctly #<User:0x00007ff02e2e08d0>
end
end
end
view:
<%= Current.user.class %>
=> NilClass