一方面,我有一个可安装的发动机,比如说前轮
前面包含我的资产和几页
它与 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
我的 preprend_front 方法创建了这个:~/main_app/app/views/front
我尝试强制添加正确的路径(但它看起来很脏):
prepend_view_path "#{Rails.root}/vendor/private_gems/front-0.0.2/app/views/front"
我不工作,只是让应用程序崩溃......
我被困在这里了。也许我的设计是错误的?