我正在寻找解析路由路径的方法,如下所示:
ActionController::Routing.new("post_path").parse
#=> {:controller => "posts", :action => "index"}
应该是相反的url_for
Upd
我发现:Rails 中 url_for 的反义词是什么?一个接受路径并生成解释路径的函数?
ActionController::Routing::Routes.recognize_path("/posts")
所以现在我需要转换posts_path
进入“/帖子”
在 Rails 3 中,您可以执行以下操作:
Rails.application.routes.recognize_path "/accounts/1"
# {:action=>"show", :controller=>"accounts", :id=>"1"}
Using ActionController::Routing::Routes.recognize_path
一直扔
ActionController::RoutingError 异常:没有路由匹配“/accounts/1
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)