Search code examples
ruby-on-railsruby-on-rails-4namespacesrubygemsruby-on-rails-5

Is it possible to keep different folders for different applications in the root level of RoR project


This is what I'm trying to achieve. I want to build an application with an admin and client portal. So I want to build a single RoR application for both these portals and I would like to keep the code of each portal separated at the root level. So basically following is the folder structure I want to have in my project.

/admin
/client
/modals
/config
/db

... ...

So I want to keep controllers, views, and other stuff relevant to each project in each folder separately.

So I want to move the modal folder to the root level as well. I read about the namespaces in RoR, but as I understand I'm unable to do it with namespaces alone. I guess I need to do some configuration level changers, don't I?

Please let me know if there is a way to do this.

Thank You.


Solution

  • What you're suggesting sounds like 5 Rails apps running independently. Does each one of those directories have its own Gemfile, database?

    It would be possible to do what you want, but it will almost certainly be more trouble than it's worth. You'll have to override some path configurations, make adjustments to connect the models/views/controllers directories for each entity (https://guides.rubyonrails.org/action_view_overview.html#view-paths), and probably much more. Rails is an opinionated framework and it doesn't do things like this gracefully.

    The 'Rails' way to do it would be to:

    1. Add some namespace routes for each of your directories
    2. Add app/models/admin app/views/admin app/controllers/admin etc. directories
    3. Namespace your model/view/controller files. e.g. class Admin::SomeController < ApplicationController

    If each of those is really its own app, then you would probably want to create a repository for each of them so that they're in version control separately.