Rails open-uri在路径上中断 [英] Rails open-uri breaking on path

查看:89
本文介绍了Rails open-uri在路径上中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用open-uri获取网址.

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

我的代码非常简单


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

   return render :text => url.to_json

运行此代码时,出现超时错误.

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

当我只请求"http://localhost:3000"时,我得到了我的主页(正确). 因此,这似乎在某处的道路上正在中断. 我尝试将net-http与uri一起使用(不确定是否会有所作为),但我仍然遇到相同的问题.我想获取路径和查询,但似乎无法正常工作.

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.

推荐答案

当然:我猜您正在使用默认的Webrick服务器,该服务器一次只能处理一个请求:

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

您的open通话消耗了一个

两种解决方案:

  • 用稀薄或独角兽之类的东西替换开发人员中的webrick

  • replace webrick in dev with thin or unicorn or whatever

使用webrick启动两台服务器:rails s& rails s -p 3001.一个在端口3000上,另一个在端口3001上

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

这篇关于Rails open-uri在路径上中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆