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

StackOverflow https://stackoverflow.com/questions/20872859

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. Engine B mounts engine A and engine B's model or controller will call logger method in engine A for logging. Is there a way logger method in engine A could be called by engine B without using include or require? Basically we want logger method in engine A to be automatically available for any other engines which mount it.

有帮助吗?

解决方案

In your engine's application controllers, inherit from parent application controller:

module EngineA
  class ApplicationController < ::ApplicationController
  ..
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top