4

I'm trying to get a url using open-uri.

my code is outrageously simple

   url = open("http://localhost:3000/descriptions")

   return render :text => url.to_json

When I run this code, I get a timeout error.

When I request just "http://localhost:3000", I get my home page (which is correct). So it seems this is breaking on the path somewhere. I've tried using net-http with uri (not sure if that would make a difference) and I still have the same issue. I want to get a path and a query, but I can't seem to get that to work.

apneadiving
  • 114,565
  • 26
  • 219
  • 213
pedalpete
  • 21,076
  • 45
  • 128
  • 239
  • Break up the URL into domain/path and open() that - the Net::HTTP documentation in Ruby describes this. – zetavolt Aug 17 '11 at 20:56

1 Answers1

6

Of course: I guess you're using the default webrick server which is only able to handle one request at a time:

  • one is consumed by your controller's action

  • one is consumed by your open call

Two solutions:

  • replace webrick in dev with thin or unicorn or whatever

  • launch two servers with webrick: rails s & rails s -p 3001. One on port 3000, another on port 3001

apneadiving
  • 114,565
  • 26
  • 219
  • 213
  • That was exactly it. I didn't realize webrick only allowed one request at a time. Strange that it would retrieve the homepage and only break on the path though. Good to know that is the reason. – pedalpete Aug 17 '11 at 22:39