可安装的引擎 Controller 方法:
module ServiceApi
module Api
module V1
class RequestorController < ApplicationController
def get_details(query_parameters)
#some code here
end
end
end
end
end
Rails应用程序 Controller 从可挂载引擎调用
get_details(params)
方法ServiceApi::Api::V1::RequestorController.new.get_details(params)
最佳答案
在我看来,您似乎不是在寻找 Controller Action ,而是在寻找一种辅助方法。例如, Controller Action 不带参数。
如果您仍然希望按说明将其保留在 Controller 中,那很好,但是您可以将其提取到帮助器中,并将该帮助器包含在要使用它的每个 Controller 中。
例如,
# [engine]/app/helpers/requestor_helper.rb
module ServiceApi::Api::V1::RequestorHelper
def get_details(query_parameters)
# code
end
end
然后在您的 Controller 中
include ServiceApi::Api::V1::RequestorHelper
当您想要的是module时,无需滥用类。
关于ruby-on-rails - 如何从Rails应用程序调用Rails可挂载引擎方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29529938/