Achaius
Achaius

Reputation: 6124

How to convert hash into request url?

I am having the hash with following keys

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

I want to build a complete request url using this hash keys. I tried using ActionDispatch::Routing::RouteSet class, but I couldn't able to get the url as expected.

I want to build the url like http://localhost:3000/users?search=John

How to get this request url?

Upvotes: 0

Views: 339

Answers (1)

Muntasim
Muntasim

Reputation: 6786

url_for(hash)

in your case:

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

returns /users?search=John host_name will be added automatically.

If you explicitly want to add host_name you can pass host: key in your hash

Upvotes: 2

Related Questions