1

有没有办法从rails中路由的速记字符串表示中获取完整路径url?

即来自 rake 路由输出的字符串,terms#index它创建了它映射的完整路径,例如http://what-ever.com/terms-and-conditions

4

2 回答 2

3

也许url_for可以帮助你?文档在这里。它没有使用确切的字符串,但取决于你在做什么,也许你可以通过将变量放在里面来获得类似的结果。

就像是:

<%= url_for(:action => '#{action}', :controller => '#{controller}', :only_path => false %>

只是一个猜测。实际上不知道它是否会起作用:)。

于 2012-09-25T05:21:31.170 回答
0

如果

rake routes --trace
          terms GET    /terms(.:format)             terms#index

然后我认为以下将起作用

terms_path #Gives /terms

terms_url #Gives http://what-ever.com/terms
于 2012-09-25T03:29:15.317 回答