[英]How to call a method in ApplicationController?
I have a method defined in ApplicationController
: 我有一个在
ApplicationController
定义的方法:
def some_checking
...
end
And I would like to call it from within another controller. 我想从另一个控制器中调用它。 Eg:
例如:
class OtherController < ApplicationController
some_checking
def xxx
end
end
How can I accomplish this? 我该怎么做? I just can't get into
some_checking
. 我只是无法进入
some_checking
。
I'm not quite sure on what you want to do. 我不太确定你想做什么。 If I've understood you've defined a method on ApplicationController and you want it to be called inside OtherController.
如果我了解您已经在ApplicationController上定义了一个方法,并且希望在OtherController中调用它。 To do this you can both use
before_filter
or just call the method from inside the xxx
method itself. 为此,您都可以使用
before_filter
或只从xxx
方法本身内部调用该方法。
Take a look to available filters here http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html 在此处查看可用的过滤器http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.