动态嵌套命名空间路由 Rails

Dynamic Nested Namespace Routing Rails

我正在用我的 routes.rb

namespace :main do
    get "/" => 'sites#index'
    get "/:action" => 'sites#:action'
    
    namespace :dashboard do
        get '/' => 'dashboards#index'
        resources :masters
    end
  end

静态 :main 命名空间的所有结果都是成功的

localhost/main/index

localhost/main/dashboard/:action

但我想通过读取参数[:master_url] 使主路由动态,例如

localhost/blog1/dashboard/:action

localhost/blog2/dashboard/:action

我正在尝试在下面添加基于 on this tuts

的代码
get ':master_url/:controller(/:action(/:id))', controller: /main\/[^\/]+/

但访问失败

localhost/url1/index

非常感谢任何帮助

您可以为命名空间提供路径参数:

namespace :main, path: ':master_url'

reference