我不確定這個答案是否及時。
Q1。當前登錄的AdminUser只能訪問他自己的資產。
A1。使用cancan作爲您的授權框架。默認情況下,ActiveAdmin不會爲您提供授權功能。所以,關鍵代碼可能看起來像:
# in your app/models/ability.rb
class Ability
include CanCan::Ability
def initialize(user)
can :read, Asset, :admin_user_id => user.id
end
end
使用慘慘(很容易,你可以解決它在15分鐘內)的更詳細的步驟,請參考:https://github.com/ryanb/cancan
Q2。當前登錄的AdminUser被設置爲每個newluyy創建的資產的admin_user_id字段。
A2:AdminUser只是一個「用戶」模型。因此,您可以在視圖和控制器中將其稱爲「current_user」,就像常規設計一樣。例如
#in your controller
def create_xx
# save the admin_user_id to the newly created asset.
Asset.create(:admin_user_id => current_user.id)
end
爲設計的更多細節,請參見其官方網站:https://github.com/plataformatec/devise