2013-05-09 20 views
10

Tôi muốn biết cách để người dùng hiện tại đăng nhập qua GUI quản trị hoạt động?Làm cách nào để người dùng hiện tại đăng nhập qua quản trị viên đang hoạt động?

Trang chủ: http://www.activeadmin.info/

Cảm ơn trước

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 

CẬP NHẬT

Khi tôi cố gắng sử dụng phương thức 'current_user' trong bảng điều khiển.rb hoặc bất kỳ tệp liên quan đến quản trị viên hiện hoạt nào, có vẻ như nó không được triển khai.

OUTPUT

undefined local variable or method `current_user' for 

Trả lời

20

Người dùng quản trị hoạt động được gọi là AdminUser theo mặc định. Do đó, phương thức trợ giúp tìm ra tương ứng là current_admin_user.

+0

Cảm ơn. Nó hoạt động! Ví dụ: logger.debug "Người dùng quản trị hiện tại: # {current_admin_user.email}" – ipegasus

0

tải lại trang và xem trong terminal của bạn, trong trường hợp này, đặt CURRENT_USER đúng đăng nhập email.

index do 
    column :name 
    column :email 
    column :slug 
    column :partner 
    puts current_user.email 
    default_actions 
end 
+0

Nhờ sự giúp đỡ của bạn. Hệ thống trả về: biến cục bộ không xác định hoặc phương thức 'current_user '. Có vẻ như phương thức 'curret_user' cần được triển khai – ipegasus

0

ActiveAdmin v1.x

index do 
    selectable_column 
    column :id 
    column :name 
    column :current_user_email do 
    current_user.try(:email) 
    end 
    actions 
end 
Các vấn đề liên quan