Rails 5.x 中动态路由如何指定 namespace

liyangmsn · January 04, 2017 · Last by flemon1986 replied at January 04, 2017 · 1601 hits

get ':controller(/:action(/:id))' 像这样的动态路由在 routes 中如何指定 controller 的 namespace

#1 楼 @huacnlee 非常感谢,这些文档之前都有看过,这个方法会报错::controller segment is not allowed within a namespace block

scope namespace: 'xxx' do
  controller :xxx do 
  end
end

#2 楼 @liyangmsn 贴代码你这么写 namespace 的

namespace :app do
  get ':controller(/:action(/:id))'
end

#4 楼 @huacnlee

get 'app/:controller(/:action(/:id))', controller: /app\/[^\/]+/

不建议把 Route 写成这样

#6 楼 @huacnlee 官方文档是这样写的 但是这样的话 url 前面就必须加 app 才行

没懂你想达到什么效果,你想灵活指定 controller 和 url 的话用scope试试

You need to Sign in before reply, if you don't have an account, please Sign up first.