Question

I am trying to use alchemy-cms within an existing app. I have an application layout including a menu bar which is linking to several controllers in my page.

I have mounted alchemy-cms as engine, which works fine.

When rendering a page created with Alchemy in my application layout, I get a routing error, because my other controllers are not available within the Alchemy engine and its page_controller which is rendering the site (at least that seems to be problem).

What I want to do is have some pages created/rendered by the Alchemy engine and some pages are created by other controllers. Isn't that possible?

Or, more generally: Is it possible to access the routes from the main application inside a mounted engine?

Was it helpful?

Solution

What I want to do is have some pages created/rendered by the Alchemy engine and some pages are created by other controllers. Isn't that possible?

It is.

You should mount Alchemy at the latest point of your routes file. (After your custom routes, because Alchemy comes with a catch all route)

That means if one of your custom routes matches - it will be used. The Alchemy routes will be used if nothing else has matched before.

# routes.rb
MyApp::Application.routes.draw do
  ... all your custom routes ...
  mount Alchemy::Engine => '/'
end

Or, more generally: Is it possible to access the routes from the main application inside a mounted engine?

I think your question is not how to access the main apps routes from within the Alchemy engine because you are working in your main app, not in Alchemy - Alchemy just comes in as a gem.

You can always access your main apps route object like this:

main_app.routes

Or the url helpers:

main_app.new_photo_path

You can access the engines routes (in this case Alchemy) with this helper:

alchemy.routes
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top