Ruby on rails 动态嵌套命名空间路由轨道
我是用我的routes.rb做这件事的 使用static:main名称空间的所有结果都是成功的 localhost/main/index localhost/main/dashboard/:操作 但是我想通过读取参数[:master_url]来动态路由main,比如 localhost/blog1/dashboard/:操作 localhost/blog2/dashboard/:操作 我试着在下面添加代码 但访问时失败 localhost/url1/indexRuby on rails 动态嵌套命名空间路由轨道,ruby-on-rails,routing,nested,Ruby On Rails,Routing,Nested,我是用我的routes.rb做这件事的 使用static:main名称空间的所有结果都是成功的 localhost/main/index localhost/main/dashboard/:操作 但是我想通过读取参数[:master_url]来动态路由main,比如 localhost/blog1/dashboard/:操作 localhost/blog2/dashboard/:操作 我试着在下面添加代码 但访问时失败 localhost/url1/index 非常感谢您的帮助。您可以为命名空间
非常感谢您的帮助。您可以为命名空间提供path参数:
namespace :main, path: ':master_url'
太棒了!但仅针对主名称空间的动态路由,它会打断仪表板路径,它会说action dashboard not exist:/。它将生成路由/:master_url/:action,该路由将由sites:action处理。不是吗?好吧,我知道了,我想这是一个路由问题。但对于这个话题来说,它已经足够解决了。非常感谢@Rodrigo;
get ':master_url/:controller(/:action(/:id))', controller: /main\/[^\/]+/
namespace :main, path: ':master_url'