确定路径是否在Rails控制器中作为路由存在 [英] Determine if path exists as route in Rails controller

查看:39
本文介绍了确定路径是否在Rails控制器中作为路由存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以将任意路径映射到一条路线

I want to know if an arbitrary path can be mapped to a route

recognized_request_for完成了我想要的操作,但无法在控制器中正常工作。

recognized_request_for accomplishes what I want, but I can't get it to work in my controller.

具体来说,如何执行可以识别_request_for 还是可以通过我的控制器完成相同任务的东西?

Specifically, how can I execute recognized_request_for or something that accomplishes the same task from my controller?

推荐答案

解决方案:

@related_page_path = '/' + @page.path
begin
  ActionController::Routing::Routes.recognize_path(@related_page_path, :method => :get)
rescue
  @related_page_path = nil
end

这篇关于确定路径是否在Rails控制器中作为路由存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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