Sam
Sam

Reputation: 1569

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).

Upvotes: 16

Views: 11758

Answers (2)

Brian Armstrong
Brian Armstrong

Reputation: 19863

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}"

Upvotes: 39

Roman
Roman

Reputation: 349

What do you think about URI::HTTP?

Upvotes: 4

Related Questions