2011-05-21 28 views
3

我有基本的間隙設置 -如何將privleges/roles添加到Clearance gem?

rails generate clearance:install 

rails generate clearance:views 

在我admin_controller,我有

before_filter :authorize 

這樣就可以確保用戶登錄我將如何設置'管理員'特權對我的用戶,並確保用戶在允許他們進入管理控制器之前擁有專有權?

有沒有更好的解決方案呢?

謝謝!

安德魯

回答

6

混合它我有同樣的問題,但cancan似乎太多了,我(小項目)

其實source codeauthorize很簡單,所以我的做法在這裏:

在初始打開Clearance::Authorization模塊,並添加自定義方法有:

# config/initializers/clearance_authorization.rb 

module Clearance 
    module Authorization 
    extend ActiveSupport::Concern 

    def authorize_admin 
     unless(signed_in? && current_user.admin?) 
     deny_access 
     end 
    end 
    end 
end 

不要忘記重新啓動服務器:)

相關問題