我知道 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 有这样的功能吗?我希望我只是在这里错过了一些明显的东西......