Ben Downey
Ben Downey

Reputation: 2665

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?

Upvotes: 12

Views: 3256

Answers (1)

maxhm10
maxhm10

Reputation: 1042

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

Upvotes: 3

Related Questions