2016-05-06 193 views
0

我有一個基於RC#386的自動授權系統。我注意到GuestPermission班和MemberPermision班之間有很多重複。不按預期繼承的類繼承

class GuestPremission < BasePermission 
    allow_action :static, [:about, :careers, :contact, :help, :home] 
end 

class MemberPermission < BasePermission 
    allow_action :static, [:about, :careers, :contact, :help, :home] 
end 

無論從BasePermission繼承。我想重構MemberPermission類從GuestPermission繼承,而不是像這樣:

class GuestPermission < BasePermission 
    allow_action :static, [:about, :careers, :contact, :help, :home] 
end 

class MemberPermission < GuestPermission 
    ... 
end 

理想情況下,應減少已被授予和存在於GuestPermissionMemberPermission重複。但是,我得到一個遞歸錯誤:filter chain haled as :authorize rendered or redirected

這通常會告訴我所請求的控制器#操作(在本例中爲static#home)未被隱式授權。但在這種情況下,它應該從GuestPermission繼承。

有關解決此問題的任何建議,以便重複權限不是必需的?

回答

0

,你可以像這樣做,使用軌道的擔憂:

module Xxx 
    extend ActiveSupport::Concern 
    included do 
     class_eval do 
     allow_action :static, [:about, :careers, :contact, :help, :home]  
     end 
    end 
end 

class GuestPremission < BasePermission 
    include Xxx 
end 

class MemberPermission < BasePermission 
    include Xxx 
end 
+0

難道不應該都涓滴如果'MemberPermission Matteo