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
4

3 回答 3

33

AdminUser默认情况下会调用活动管理员用户。因此,相应的设计辅助方法是current_admin_user.

于 2013-05-09T21:32:59.377 回答
1

ActiveAdmin v1.x

index do
  selectable_column
  column :id
  column :name
  column :current_user_email do
    current_user.try(:email)
  end
  actions
end
于 2016-03-21T12:28:33.973 回答
0

重新加载页面并在您的终端中查看,在这种情况下,放置正确的 current_user 记录的电子邮件。

index do
    column :name
    column :email
    column :slug
    column :partner
    puts current_user.email
    default_actions
end
于 2013-05-09T20:33:31.080 回答