Here I want to render the layout of engine's parent application, i.e. in hierarchy engine's parent application.html.erb should be higher. But since engine has also got application.html.erb it is only rendering it and not rendering engine's parent application.html.erb.
How can i render my parent application.html.erb along with my engine application.html.erb
Thanks
2.2. By default, if you use the :plain option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the layout: true option and use the . text. erb extension for the layout file.
The layouts removes code duplication in view layer. You are able to slice all your application pages to blocks such as header, footer, sidebar, body and etc. This is an example of typical web application page, almost every site has these blocks. And as a rule the body block differs on each page.
In Rails, layouts are pieces that fit together (for example header, footer, menus, etc) to make a complete view. An application may have as many layouts as you want. Rails use convention over configuration to automatically pair up layouts with respective controllers having same name.
Rails Guides describes partials this way: Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.
In your engine controller you can use:
layout 'application'
in order to render the application layout or you can switch to:
layout 'engine_name/application'
to load the engine's layout.
I don't know if you can load them both (engine layout should only inherit from application layout and extend it) but I hope it gets you further at least.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With