简体   繁体   中英

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.

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM