Route analysis in rails
I am looking for a method to parse a route route as follows:
ActionController::Routing.new("post_path").parse
#=> {:controller => "posts", :action => "index"}
It should be opposite url_for
Update
I found out:
What is the opposite of url_for in Rails? A function that takes a path and generates an interpreted route?
ActionController::Routing::Routes.recognize_path("/posts")
So now I need to convert posts_pathto "/ posts"
Here is the method:
>> ActionController::Routing::Routes.recognize_path("/posts/")
=> {:action=>"index", :controller=>"posts"}
If you only have a line with your route (e.g. "posts_path"), then I assume that in the context you are using, you should be able to do
ActionController::Routing::Routes.recognize_path(send("posts_path".to_sym))
By the way, this also helped me :)