Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6079113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:54:35+00:00 2026-05-23T10:54:35+00:00

Given that I have controllers: app/controllers/app1/users_controller.rb app/controllers/app2/users_controller.rb I have in my routes file: [app1,

  • 0

Given that I have controllers:

  app/controllers/app1/users_controller.rb
  app/controllers/app2/users_controller.rb

I have in my routes file:

["app1", "app2"].each do |n|

  constraints(:host => "#{n}.com") do
    scope({:as => vn, :module => vn}) do
      resources :users
    end
  end

end

This gives me routes like so:

GET app1_users_path (app1.com/users) { :controller => "app1/users", :action => "index" }
GET app2_users_path (app2.com/users) { :controller => "app2/users", :action => "index" }

I do this for every path, for every “app” in my application.

The problem is, as the no. of both apps and paths grows, so does the no. of paths

n = no_of_paths
a = no_of_apps
(n * a) = "LOADS"

Can anyone think of a way I can set the “module” part of my routes (the controller prefix) as a wildcard so I only have to name each route once?

Something like:

match ":controller/:action(/:id)" => ":host/:controller#:action"

maybe?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:54:35+00:00Added an answer on May 23, 2026 at 10:54 am

    I’ve solved this…

    Essentially, I was asking the wrong question.

    My application serves more than one website so I thought it was prudent to create a controller (and therefore a route) for each “vertical” (site within my app).

    The shared behaviour in these controllers went into a module which I included in each controller. ie:

    # vertical1/users_controller.rb
    class Vertical1::UsersController < ApplicationController
      include UsersControllerTemplate
    end
    
    # vertical2/users_controller.rb
    class Vertical2::UsersController < ApplicationController
      include UsersControllerTemplate
    end
    
    # lib/users_controller_template.rb
    module UsersContrllerTemplate
    
      def index() end
    
    end
    

    In practise, I found that 95% of the time I stuck with the shared behaviour.
    Having separate controllers and routes was overkill.

    Working fine (and faster) now with one instance for most controllers and one or two name-spaced controllers where I need to customise the behaviour.

    I’ve also decided to inherit custom controllers from the default behaviour (rather than include modules):

    # vertical1/users_controller.rb
    class Vertical1::UsersController < UsersController
      # change some stuff here
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that I have this resultset structure (superfluous fields have been stripped) Id |
Given that I have a custom PHP error handler already, does it make sense
Given that I have a table that holds vehicle information and one of those
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
Given that I only have one monitor, what's the best way to debug a
Given that two branches have diverged and a specific commit from one branch (and
What alternatives are there to GAE, given that I already have a good bit
Given that django-nonrel has got JOINs working, does this mean we have M2M fields
I have just started migrating my homegrown persistence framework to JPA. Given that the
datetime.datetime.utcnow() Why does this datetime not have any timezone info given that it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.