12

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?

Ben Downey
  • 2,575
  • 4
  • 37
  • 57
  • Maybe, this one helps you? http://stackoverflow.com/a/7175241/1005661 – Vitalyp Mar 11 '14 at 02:29
  • I found this post, which answers my question: [http://stackoverflow.com/questions/10615067/render-engine-within-application-layout][1] [1]: http://stackoverflow.com/questions/10615067/render-engine-within-application-layout – Ben Downey Mar 11 '14 at 03:06
  • You have a couple options 1) make your engine controllers inherit from main application's ApplicationController and use the main application layout. You can use this in your engine application_controller: class ApplicationController < ::ApplicationController 2) You can fix the problem with your routes in your view overrides by prepending your paths with main_app (eg: main_app.resource_path) – Gabriel Oliveira Jan 18 '16 at 01:32

1 Answers1

3

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

maxhm10
  • 1,034
  • 9
  • 20