2014-10-28 83 views
0

我有這樣的: ability.rb主動聯繫康康舞的ActiveRecord :: RecordNotFound在管理:: AdminUsersController#顯示

def initialize(user)  
     if user.admin? 
     can :manage, :all 
     else 
     can :manage, AdminUser, :id => user.id 
     end 
    end 

和application_controller.rb:

def access_denied(exception) 
    redirect_to admin_dashboard_path , :alert => exception.message 
end 

而且我已經加入主動管理員在intializer/active_admin.rb中的適配器:

config.authentication_method = :authenticate_admin_user! 
    config.authorization_adapter = ActiveAdmin::CanCanAdapter 
    config.on_unauthorized_access = :access_denied 

當我去t他沒有授權的網址(例如:http://admin.localhost.com:3000/admin/admin_users/1)。它的錯誤如下:

ActiveRecord::RecordNotFound in Admin::AdminUsersController#show 

任何人都可以指出我在正確的方向,因爲我在這裏失蹤。

在此先感謝。

回答

0

我已經升級寶石來active_admin寶石 'activeadmin', '0.6.3' 解決了這個問題。

0

當Active Record無法通過給定的ID或ID集找到記錄時,會引發錯誤。請檢查您是否擁有ID爲1的admin_users表中的條目。請參閱下面的圖片以更好地理解錯誤。

enter image description here

+0

是的id是存在於我的數據庫user.id 1存在,但由於當前用戶沒有權限查看其他用戶這就是爲什麼它給出的錯誤。 – railslearner 2014-10-29 06:04:35

+0

@dinshawraje好吧,似乎邏輯是以某種方式工作。具有正確憑據的用戶是否可以查看該頁面? – Roshan 2014-10-29 06:41:38

+0

是的,正確的用戶可以看到它的頁面。 – railslearner 2014-10-29 07:28:39

相關問題