也许我只是没有使用正确的Ruby术语(如果我是的话,请纠正我),但谷歌在这方面没有帮助我.
我有一个类(称为OrderController),它扩展了另一个类(称为BaseStoreController).在BaseStoreController中,我定义了一个before_filter
,它在我的整个站点中使用,除了我的OrderController之外,其余的都是小的.在这种非常特殊的情况下,我需要定义一个定制的before_filter
,它需要执行一些额外的逻辑,然后调用BaseStoreController中定义的before_filter
.
我不知道该怎么做.
以下是我try 过的,但"super"关键字似乎不是我所期望的:
class BaseStoreController < ActionController::Base
before_filter :authorize
protected
def authorize
#common authroization logic here
end
end
和
class OrderController < BaseStoreController
before_filter :authorize
protected
def authorize
#additional authroization logic here
super.authorize
end
end
我的代码的最终结果是OrderController中的authorize方法失败,出现以下错误:
You have a nil object when you didn't expect it! The error occurred while evaluating nil.authorize