Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 877
Ben Downey Avatar asked Mar 11 '14 02:03

Ben Downey


1 Answers

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

like image 147
maxhm10 Avatar answered Oct 16 '22 18:10

maxhm10