I have built a custom administration panel into a Rails application that allows content editing of certain models through a gui interface. I initially designed the “admin” app to act as a parent applications—with its MVC, Gemfile, migrations, etc.—and created sub-applications (in a directory called frontends) that act as website interfaces to the admin’s models. The sub applications inherit the MVC from the parent admin application, allowing for website frontends to be designed and build upon the existing admin architecture without continually re-developing admin sites for each new project.
The structure on my local machine currently looks like this:
Administration Application <-- Individual git repo
-> app
-> admin
-> config
...
-> frontends
-> Website_1 <-- Individual git repo
-> app
-> config
...
-> Website_2 <-- Individual git repo
-> app
-> config
...
The current frontend is identified by a simple frontend.yml file in the config that loads the frontend application in the initializer before the admin application.
I feel like it’s imprudent, however, to have a nested structured like this. First the nesting of git repos is messy on my location machine, and more importantly, it’s extremely hard to switch the context of a project in a relatively short period of time. For example, if I wanted to switch from Website_1 to Website_2, I have to quit rails server and run a rake task that switches frontends. It also becomes a little more cumbersome when a frontend uses a different branch of the administration application. I find myself spending a lot of wasted time in git and rake switching between contexts in order to continue development on my projects.
I would like to change the structure of the application where each frontend is its own independent Rails application. It seems this would make it more simple to switch development contexts—allowing more than one application at a time to be running in rails server, testing, etc. I also want to be able to continue to house the administration application under git—since there are different flavors of the app throughout a series of branches and tags.
What would be the best way to approach this reconfiguration? I was thinking of creating a gem of the administration application and loading it from Bundler.
I think a gem is your best bet here. Specifically, I’d look into using an engine; an engine is a gem that’s directly mountable inside your routes.rb using something like this:
Engines are essentially mini-applications that mount directly into other applications, which sounds like precisely what you need here.
For more information on how to get started, check out the Rails engine documentation. And here’s a handy walkthrough you can follow that includes a link to enginex, a quick generator to bootstrap engine gems.