正则表达式 [英] regex on routes

查看:112
本文介绍了正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的路由

  namespace :api, defaults: {format: 'json'} do
    namespace :v1 do
      match 'recepcao/produto' => 'recepcoes#produto'
      match 'recepcao/nota'    => 'recepcoes#nota'
      match 'recepcao/venda'   => 'recepcoes#venda'
      match 'recepcao/cliente' => 'recepcoes#cliente'
      match 'recepcao/status' => 'recepcoes#status'
    end
  end

我想我会还有更多操作,而且我不想继续在自己的路线上添加匹配

是否可以执行类似

I guess I'll have more actions, and i don't want to keep adding matchon my routes
is there a way to do something like

  namespace :api, defaults: {format: 'json'} do
    namespace :v1 do
      match 'recepcao/*' => 'recepcoes#*'
    end
  end


推荐答案

当然,请像默认路由一样放置一个占位符:

Of course, put a placeholder like the default route:

# match ':controller(/:action(/:id(.:format)))'

不需要正则表达式。请参阅Rails路由文档的动态细分部分

No need for a regex. See the Dynamic Segments portion of the Rails routing docs.

这篇关于正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆