我知道before_filter只适用于Rails中的控制器,但是对于模型我想要这样的东西:每次调用模型中的方法时,我都想运行一个方法来确定被调用的方法是否应该运行。从概念上讲,这样的事情:
class Website < ActiveRecord::Base
before_filter :confirm_company
def confirm_company
if self.parent.thing == false?
return false
end
end
def method1
#do stuff
end
end
因此,当我调用@ website.method1时,它将首先调用confirm_company,如果我返回false,则不会运行method1。 Rails有这样的功能吗?我希望我只是错过了一些明显的东西......