2010-04-14 57 views
0

我在ApplicationController定义的方法:如何在ApplicationController中调用方法?

def some_checking 
    ... 
end 

而且我想从另一个控制器中调用它。例如:

class OtherController < ApplicationController 

    some_checking 

    def xxx 
    end 

end 

我该如何做到这一点?我无法进入some_checking

回答

3

我不太清楚你想做什么。如果我明白你已经在ApplicationController上定义了一个方法,并且你希望它在OtherController中被调用。要做到这一点,你既可以使用before_filter,也可以直接调用xxx方法本身的方法。

看看这里可用的过滤器http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html

+0

谢谢。在这种情况下,我忘了我必须使用before_filter。 >< – 2010-04-14 08:28:59

相关问题