简体   繁体   English

如何在宿主应用程序中呈现Rails引擎的视图

[英]How to render a Rails engine's views inside the host app

I need some help getting a rails engine to communicate with my host application. 我需要一些帮助让rails引擎与我的主机应用程序通信。

I've got a standard layout file in the engine. 我在引擎中有一个标准的布局文件。

app/views/layouts/my_engine/application.html.erb

and my host app has the standard 我的主机应用程序有标准

app/views/layouts/application.html.erb

In the host app, I've gota partial that contains a nav bar. 在主机应用程序中,我有一个包含导航栏的部分内容。 I would like to use this nav bar in pages that are generated by the engine. 我想在引擎生成的页面中使用此导航栏。

I have no idea how to do this. 我不知道该怎么做。

My first attempt at solving this was to create another version of this file in my host app, thereby overwriting the original behavior. 我解决此问题的第一个尝试是在我的主机应用程序中创建此文件的另一个版本,从而覆盖原始行为。

app/views/layouts/my_engine/application.html.erb

I was hoping this strategy would work, but the nav bar partial now has no knowledge of the routes that belong to the host app. 我希望这个策略可行,但导航栏部分现在不知道属于主机应用程序的路由。 It throws a 'no method' error on any named route in the host app. 它会在主机应用程序中的任何命名路由上引发“无方法”错误。

So how do I allow the engine to render views in the host app, but ultimately rely on the host app's structure for pages as defined in app/views/layouts/application.html.erb ? 那么我如何允许引擎在主机应用程序中呈现视图,但最终依赖于app/views/layouts/application.html.erb定义的主机应用程序的页面结构?

Copying this from the comments, so that other people don't miss it: 从评论中复制此内容,以便其他人不会错过它:

I found this post, which answers my question: Render engine within application layout 我找到了这篇文章,它回答了我的问题: 在应用程序布局中渲染引擎

credit to OP for finding the solution 感谢OP寻找解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有相同模型名称的主机应用程序和引擎,使用主机应用程序的部分,导轨从引擎内部渲染主机应用程序的模型 - Host app and engine with same model name, rendering host app's model from inside engine using host app's partial, rails 用于定制现有应用程序视图的好的Rails CMS引擎是什么? - What's a good Rails CMS engine for customization of existing app views? Rails引擎的静态资产未在主机应用程序中提供 - Rails engine's static assets not being served in host app 如何设置 Rails 引擎语言环境(它使用 :en 甚至强硬的主机应用程序也有不同的语言环境) - How to set Rails engine locale (it's using :en even tough host app has a different locale) 主机视图中不可用的引擎路线 - Engine's routes not available in host's views Rails 7 引擎如何使未编译的样式表可用于托管应用程序? - Rails 7 engine how to make uncompiled stylesheets available to host app? Rails Engine仅将中间件添加到主机应用程序 - Rails Engine add middleware to host app only 无法在我的Rails应用中渲染视图 - Unable to render views in my Rails App 轨道应用程序内的轨道引擎中的 Inheritance - Inheritance in rails engine that is inside a rails app 如何在应用程序模型内部选择Rails引擎模型 - How to co-opt Rails engine model inside app model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM