0

我想检索我在 Rails 应用程序中访问的页面的实际编码 URL 值。

所以,如果我访问http://domain.com/dir/test%2Bpath,我应该得到值 "http://domain.com/dir/test%2Bpath" 而不是 "http://domain.com/目录/测试+路径”。

有没有办法做到这一点?我检查了 Request 对象,谷歌搜索......什么都没有。

4

2 回答 2

1

在我的系统中,我可以使用request.urland request.path

(rdb:1) request.url
"http://localhost:3000/test2/path/a%2Bb"
(rdb:1) request.path
"/test2/path/a%2Bb"

这应该在控制器或视图中工作。

于 2012-04-27T02:15:48.157 回答
0

您可以使用 ruby​​ 辅助方法

URI.unescape('http://domain.com/dir/test%2Bpath')
于 2012-04-27T01:47:45.493 回答