一方面,我有一个可安装的引擎,假设 Front Front 包含我的资产和几个页面,它与 MainApp 隔离。我不希望它触及主应用程序。
另一方面,我希望我的 MainApp 使用前端的布局和部分。所以我这样设置布局:
class ApplicationController < ActionController::Base
layout 'front/application'
end
但是前端/应用程序直接引用引擎部分,因为隔离,像这样
render 'header' # front/ prefix is not required
所以 MainApp 视图尝试加载 app/views/application/header 而不是 app/views/front/application/header
为了解决这个问题,我放了一个这样的 prepend_view_path :
class ApplicationController < ActionController::Base
layout 'front/application'
before_filter :prepend_front
protected
def prepend_front
prepend_view_path "app/views/front"
end
end
但这不起作用,因为引擎路径指向供应商。引擎将它自己添加到前置路径列表中:~/main_app/vendor/private_gems/front-0.0.2/app/views 我的 prepred_front 方法创建了这个:~/main_app/app/views/front
我试图强行添加正确的路径(但它看起来很脏):
prepend_view_path "#{Rails.root}/vendor/private_gems/front-0.0.2/app/views/front"
我不工作,只是让应用程序崩溃......
我被困在这里。也许我的设计错了?