我有一個接觸器,加載並通過cancancan授權的資源:覆蓋慘慘方法,這引起了異常「未初始化的不斷接觸」
class ContactsController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource
end
我的索引行爲沒有被調用,因爲跟資源,纔可以訪問在名爲MongoidContainer的名稱空間內。因此,在我的系統中訪問聯繫人的唯一方法是MongoidContainer :: Contact。因此,當cancancan嘗試加載資源,一個異常這裏提出:
module CanCan
class ControllerResource
...
def resource_class
case @options[:class]
when false then name.to_sym
when nil then namespaced_name.to_s.camelize.constantize
when String then @options[:class].constantize
else @options[:class]
end
end
...
end
end
我試圖重寫ContactsController這種方法,但覆蓋永遠不會被調用。該模塊很可能不包含在ApplicationController名稱空間中。我怎樣才能重寫這個方法?
我沒有看到說你可以傳遞類選項這樣其運作選項:
load_and_authorize_resource class: 'MongoidContainer::Contact'
我只是真的很好奇,爲什麼該方法在這種情況下沒有被覆蓋。