简体   繁体   English

如何使在Rails引擎的应用程序控制器中定义的方法自动适用于安装它的任何其他引擎?

[英]How to make method defined in a rails engine's application controller automatically available for any other engines which mount it?

Rails 3.2 engine A is a logger engine and there is a logger method (create an entry in log table) defined in its application controller . Rails 3.2 engine A是一个记录器引擎,并且在其application controller定义了一个logger方法(在日志表中创建条目)。 Engine B mounts engine A and engine B's model or controller will call logger method in engine A for logging. Engine B安装了engine Aengine B's modelcontroller将调用引擎A中的记录器方法进行记录。 Is there a way logger method in engine A could be called by engine B without using include or require ? engine B是否可以在不使用includerequire情况下调用engine A logger方法? Basically we want logger method in engine A to be automatically available for any other engines which mount it. 基本上,我们希望engine A logger方法可自动用于安装它的任何其他引擎。

In your engine's application controllers, inherit from parent application controller: 在引擎的应用程序控制器中,从父应用程序控制器继承:

module EngineA
  class ApplicationController < ::ApplicationController
  ..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM