0

我有以下键的哈希

{:action=>'index', :controller=>'users', :search=>'John'}

我想使用这个哈希键构建一个完整的请求 url。我尝试使用ActionDispatch::Routing::RouteSet类,但无法按预期获取 url。

我想建立这样的网址http://localhost:3000/users?search=John

如何获取此请求 url?

4

1 回答 1

2
url_for(hash)

在你的情况下:

url_for(:action=>'index', :controller=>'users', :search=>'John')

返回/users?search=Johnhost_name 将自动添加。

如果您明确想要添加 host_name ,您可以在您的哈希中传递 host: key

于 2013-06-24T12:40:28.033 回答