【发布时间】:2015-10-18 11:30:16
【问题描述】:
如果我有 @post 之类的资源,有没有办法获取指向该资源路径的 url,例如:
@post.to_url
url_for(@post)
path_to(@post)
@post.to_path...
你得到了理想
【问题讨论】:
标签: ruby-on-rails
如果我有 @post 之类的资源,有没有办法获取指向该资源路径的 url,例如:
@post.to_url
url_for(@post)
path_to(@post)
@post.to_path...
你得到了理想
【问题讨论】:
标签: ruby-on-rails
给定一个像@post 这样的资源,url_for 将返回路径。
url_for(@post) #=> "/posts/1"
从控制台:
app.url_for(@post) #=> "http://www.example.com/posts/1"
app.post_path(@post) #=> "/posts/1"
见:
【讨论】:
app.url_for(@post)。