Rails 中 url_for 的反义词是什么?一个接受路径并生成解释路径的函数?
大脑有点炸了......我如何从相对路径中获取 :controller 和 :action 的哈希值?
这基本上与 url_for 相反。在下面的示例中,“some_function”是我正在寻找的神秘函数名称...我知道这很简单,只是不记得或似乎能够在文档中找到它。
就像这样:
some_function('/posts/1/edit')
=> {:controller => 'posts', :action => 'edit', :id => '1'}
Brain's a little fried....How do I get a hash of the :controller and :action from a relative_path?
This is basically the opposite of url_for. in the example below, "some_function" is the mystery function name I'm looking for...I know it's easy, just can't remember or seem to be able to find it in the docs.
Like so:
some_function('/posts/1/edit')
=> {:controller => 'posts', :action => 'edit', :id => '1'}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Rspec 有一个方法“params_for”,它使用 Action Controller 的路由方法将带有方法的路径解析为路由。
他们的比这更强大一点,但归结为:
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:
对于 Rails 3,最好的方法是使用
With Rails 3 the best way is to use