2011-12-08 48 views
1

有沒有什麼辦法可以限制某些用戶只能在rails_admin中看到他們自己的內容?Rails_Admin用戶控件

基本上說,在地理區域內有一羣偵察領導人,我希望有許多領導人,然後只允許他們看到他們創建的項目。

我需要爲他們分配一個地理標識,然後添加設計?

回答

3

我通常使用CanCan來做到這一點。如果相關用戶是當前用戶,您可以添加檢查。一個慘慘配置鋼軌管理的

例(ability.rb),對於複雜的例子看rails_admin wiki on CanCan

class Ability 
    include CanCan::Ability 

    def initialize(user) 
    if user 
     can :access, :rails_admin 
     if user.role? :employee 
     can :read, [Model1, Model2, Model3] 
     can :update, User, :id => user.id #employee can update own user details 
     elsif user.role? :admin 
     can :manage, :all 
     end 
    end 
    end 
end 

,並檢查作用agains你的用戶,添加/更改您的用戶模型

以下
# Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me, :role 

    def role_enum 
    %w[admin employee] 
    end 

def role?(role) 
    self.role == role.to_s 
end