Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails engine: render parent application layout

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

like image 674
Paritosh Singh Avatar asked Jul 20 '12 11:07

Paritosh Singh


People also ask

How can you tell Rails to render without a layout?

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.

How should you use nested layouts in Rails?

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.

What are layouts in Rails?

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.

What is render partial in Rails?

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.


1 Answers

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.

like image 189
Romeo Mihalcea Avatar answered Sep 26 '22 10:09

Romeo Mihalcea