What is the opposite of url_for in Rails? A function that takes a path and generates the interpreted route? What is the opposite of url_for in Rails? A function that takes a path and generates the interpreted route? ruby ruby

What is the opposite of url_for in Rails? A function that takes a path and generates the interpreted route?


With Rails 3 the best way is to use

Rails.application.routes.recognize_path('/posts/1/edit')


Rspec has a method 'params_for', which uses Action Controller's Routing Methods to parse paths with methods into routes.

Theirs is a little more robust than this, but it boils down to:

def params_for(path, method)  params = ActionController::Routing::Routes.recognize_path(path, :method => method)end