Rails 请教调用 mountable engine 中 help_method 的推荐做法

zernel · May 26, 2012 · Last by Zernel replied at May 27, 2012 · 2954 hits

在 main app 里面应该怎么调用写在 engine 下 ApplicationContorller 里的 helper 方法比较合理?谢谢 :D

你可以在 main app 的 ApplicationController 中这样写helper YourEngine::Engine.helpers,这样可以在 main app 中使用所有 engine 的 helper,如果你只想用某一个就写 helper YourEngine::SomeHelper

不建议这么设计,main app 应该被 mountable engine 所依赖,本身不应该依赖任何 mountable engine

#1 楼 @kenshin54 这种做法可以调用到常规的 helper,不过 controller 里面定义的 helper_method 却调用不到。谢了:)

#2 楼 @fsword 我明白你的意思,我只是想实现某个特殊的想法所做的尝试而已,谢了 XD

#3 楼 @Zernel 如果只是 helper_method 公用,那写到 module 里 mixin 进来就好了

#5 楼 @kenshin54 嗯嗯,现在就这么做了,谢了 XD

You need to Sign in before reply, if you don't have an account, please Sign up first.