Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating an external url in rails

I want to construct a url within my rails app that points to another server that isn't running rails. Using url_for almost satisfies my requirements, but it requires a controller key which I don't need (redirecting to a top level page on the external site).

The reason I want to do this is so that I have a cleanly construct a url with a hash of arguments (some of which are determined at runtime).

like image 438
Samantha Bennett Avatar asked Sep 25 '09 22:09

Samantha Bennett


2 Answers

You can call to_query on Hash in rails which will take care of url encoding etc. So maybe something like this:

params = {
  :a => "http://google.com",
  :b => 123
}
url = "http://example.com?#{params.to_query}"
like image 107
Brian Armstrong Avatar answered Sep 18 '22 14:09

Brian Armstrong


What do you think about URI::HTTP?

like image 36
Roman Avatar answered Sep 20 '22 14:09

Roman