I would like to make an engine. My engine may be mountable or not it's not important. But I would like to use my main application layout like Devise for rendering the engine's views. This also very easy.
But! When my application's layout and rails engine's view template rendering, I got an exception because I use url helpers in my layout, but this url helpers is in my main_app. So I know I can write a main_app context before all url helpers in layout file but I don't want to do it. Devise is working this way. You don't have to write main_app.pages_url in your application layout if you view sessions/new view for example. But I don't know how they do it. I would like to know it and I've read the code I've read the documentation and I found nothing. Please somebody tell me how they do it. How can I make an engine that handle main_app url helpers like Devise. Thank you.
It depends on the kind of your engine. If your engine contains the line isolate_namespace SomeModule
, it means that the url_helpers
(and helpers in general) won't be shared between your application and the engine. So you need to resort to tools like main_app
and so forth.
That said, all that Devise does to share the layout is to simply not call isolate_namespace
, which is how engines work since when they were introduced in Rails 2.2. The isolate_namespace
feature was added on Rails 3.1 for those who wished stronger decoupling.