问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/7099331/rails-open-uri-breaking-on-path