【问题标题】:Rails, how to get the route name from the actual request (routing reverse lookup)Rails,如何从实际请求中获取路由名称(路由反向查找)
【发布时间】:2013-08-05 08:32:21
【问题描述】:

我有实际的请求,我想知道 Rails 已解决的路线名称

例如,如果我有这条路线:

front_page GET    /front/pages/:id(.:format)

而实际的请求是:

/front/pages/10 (GET)

我想要这样的结果:

front_page

【问题讨论】:

标签: ruby-on-rails-3.2 rails-routing


【解决方案1】:

恕我直言,您可以使用 KinOfCain 在How can I find out the current route in Rails? 上解释的代码

Rails.application.routes.router.recognize(request){ |route, matches, parameters| puts route.name }

路由器没有存储在任何地方识别的路由,至少我找不到它

【讨论】:

  • @fguillen 同样的方法不起作用here,有什么想法吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-04
  • 1970-01-01
  • 1970-01-01
  • 2018-05-16
  • 1970-01-01
相关资源
最近更新 更多