我正在寻找这样解析路由路径的方法:
ActionController::Routing.new("post_path").parse
#=> {:controller => "posts", :action => "index"}
应该和url_for
相反
ActionController::Routing::Routes.recognize_path("/posts")
所以现在我需要将 posts_path
转换为“/posts”
最佳答案
在 Rails 3 中,您可以执行以下操作:
Rails.application.routes.recognize_path "/accounts/1"
# {:action=>"show", :controller=>"accounts", :id=>"1"}
使用 ActionController::Routing::Routes.recognize_path
不断抛出
ActionController::RoutingError Exception: No route matches "/accounts/1
关于ruby-on-rails - rails 中的路径解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2714867/