Rails open-uri breaking on path

放肆的年华 提交于 2019-12-23 12:29:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!