简体   繁体   English

如何在ApplicationController中调用方法?

[英]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.

相关问题 在每次方法调用之前如何从ApplicationController调用方法? - How do a call a method from the ApplicationController before every method call? 如何从ApplicationController调用模型的where(…)方法 - How to call the model's where(…) method from ApplicationController 我正在测试功能,需要从ApplicationController调用方法,该怎么办? - I'm Testing features and need to call a method from ApplicationController, how can I do that? 如何在模型中调用ApplicationController中定义的方法 - How to call methods defined in ApplicationController in models 如何从ApplicationHelper调用ApplicationController方法 - How to call ApplicationController methods from ApplicationHelper 如何从其他控制器调用ApplicationController中的方法? - How to call methods in ApplicationController from other controllers? 如何在请求规范中存根ApplicationController方法 - How to stub ApplicationController method in request spec Rails:如何通过控制器的before_action / after_action方法INLINE调用带有ARGS的ApplicationController方法? - Rails: How to call ApplicationController method WITH ARGS from a controller's before_action/after_action method INLINE? 如何测试ApplicationController方法也定义为辅助方法? - How to test ApplicationController method defined also as a helper method? 等号的ApplicationController方法 - ApplicationController Method with Equal Sign
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM