我的主应用程序的应用程序控制器中有一个 before_filter 钩子,它执行以下操作:(它不只是在闪存中放置一个链接,还有一条消息,但它与问题无关,它只是访问路径方法)
class ApplicationController < ActionController::Base
before_filter :set_link
def set_link
flash[:notice] = items_path
end
end
这适用于该应用程序,但是当我进入我制作的引擎的控制器时,我得到了异常
No route matches {:controller=>"items", :action=>"index"}
我知道在引擎中,除非前缀为main_app
因此将应用程序控制器中的方法更改为
def set_link
flash[:notice] = main_app.items_path
end
摆脱异常,但我真的不想这样做。是否有另一种解决方案可以让引擎识别 main_app 路线?
编辑:
如果应用程序布局调用路径助手,也会发生这种情况。因此,如果引擎被设计为集成到 main_app 的布局中,那么这个问题也会在那里出现。