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

假装没事ソ 提交于 2019-12-04 03:17:40

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

With Rails 3 the best way is to use

Rails.application.routes.recognize_path('/posts/1/edit')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!