Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 Mountable Engines : How to use/template it inside another application?

Let's say I created a mountable engine called 'Soho' that has a controller for 'Users'. I can go to /users/1 to see my user with ID 1.

Inside 'Soho', I have a application.html.erb for layout.

Now let's assume I want to "blend" my engine 'Soho' in an application called 'Soho_test', and I mount my engine at "/". So, in my host application 'Soho_test', I can also go at /users/1 to see my user with ID 1. This is working.

My question is : how can I do in my host application 'Soho_test' to apply the 'Soho_test' application.html.erb to the /users/1 (user profile page) instead of the one in the 'Soho' mountable engine?

Thanks!

like image 419
Dominic Goulet Avatar asked Aug 09 '11 15:08

Dominic Goulet


1 Answers

I found how to achieve it, so I will post my answer on my own question, in case anyone else wonders. It is actually quite easy. I should have thought about this in the first place...

All you have to do is to create a folder in your /views/layouts/ with the name of your engine. So according to my question, it would be /views/layouts/soho/. In that folder, put the application.html.erb that you want to have.

You can do the same with partials and other views. Just create a folder /views/soho/.../ and put your files there. I havn't found a rake task to copy the engine views in my host application, so I wrote one.

like image 143
Dominic Goulet Avatar answered Sep 27 '22 17:09

Dominic Goulet