18

I would like to know how to get the current user that is logged in via the active admin GUI?

Homepage: http://www.activeadmin.info/

Thanks in advance

MODEL

admin_user.rb

class AdminUser < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, 
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :id  , :admin_permission
  # attr_accessible :title, :body
  has_one :admin_permission
  validates_uniqueness_of :email

  def self.current_logged_user
    # ?
  end
end

UPDATE

When I try to use the method 'current_user' in dashboard.rb or any active admin related file, apparently it is not implemented.

OUTPUT

undefined local variable or method `current_user' for
ipegasus
  • 14,796
  • 9
  • 52
  • 76

3 Answers3

33

The active admin user is called AdminUser by default. The corresponding devise helper method is therefore current_admin_user.

jokklan
  • 3,520
  • 17
  • 37
1

reload the page and see in your terminal, in this case, puts the correct current_user logged email.

index do
    column :name
    column :email
    column :slug
    column :partner
    puts current_user.email
    default_actions
end
  • 1
    Thanks for your help. The system returns: undefined local variable or method `current_user'. It looks like the method 'curret_user' needs to be implemented – ipegasus May 09 '13 at 20:41
  • `current_user` does work for me on Rails 5.2.6 within the block of `ActiveAdmin.register` – Vajk Hermecz Aug 30 '22 at 13:33
1

ActiveAdmin v1.x

index do
  selectable_column
  column :id
  column :name
  column :current_user_email do
    current_user.try(:email)
  end
  actions
end
Mohamed Ziata
  • 1,186
  • 1
  • 11
  • 21