Ruby 应用程序响应直到堆栈太深

发布于 2024-11-18 21:23:06 字数 1955 浏览 1 评论 0原文

我在这里不知所措。我有一个相当简单的事情,但似乎遇到了很多问题。我正在开发直接的网络爬虫。人们发布请求并将其发送到队列中。如果他们想查询队列中有什么:路由是

127.0.0.1:8080/requests/id/1.json

响应是操作 (def) CrawlerController 是控制器。 请求是模型。

这是路线:(虽然我不认为它相关)

  match 'requests/id/:id' => 'crawler#response'

这是控制器内的定义:

  def response
    @request = Request.find(params[:id])
   respond_to do |format|
     #format.html { render :action => "new"}
     format.json { render :json => @request.to_json }
    end
  end

我得到的错误是堆栈级别太深。如果我查看控制台输出:

编辑:第 21 行和第 19 行是 @respond 要做的事情,而 format.json

  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
Completed 500 Internal Server Error in 2688ms

SystemStackError (stack level too deep):
  app/controllers/crawler_controller.rb:21:in `response'
  app/controllers/crawler_controller.rb:19:in `response'
  app/controllers/crawler_controller.rb:21:in `response'
  app/controllers/crawler_controller.rb:19:in `response'
  app/controllers/crawler_controller.rb:21:in `response'
  app/controllers/crawler_controller.rb:19:in `response'

很奇怪吧?

I'm at a loss here. I have a fairly simple thing going but seem to run into problems a lot with this. I have straight forward web crawler in the works. People post requests and send it on to the queue. If they want to query whats in the queue: the route is

127.0.0.1:8080/requests/id/1.json

response is the action (def)
CrawlerController is controller.
request is the model.

Heres the route: (although I don't think its relevant)

  match 'requests/id/:id' => 'crawler#response'

And here is the def within the controller:

  def response
    @request = Request.find(params[:id])
   respond_to do |format|
     #format.html { render :action => "new"}
     format.json { render :json => @request.to_json }
    end
  end

The error I'm getting is stack level too deep. If i look at the console output:

EDIT: lines 21 and 19 are the @respond to do and format.json

  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "requests".* FROM "requests" WHERE "requests"."id" = 1 LIMIT 1
Completed 500 Internal Server Error in 2688ms

SystemStackError (stack level too deep):
  app/controllers/crawler_controller.rb:21:in `response'
  app/controllers/crawler_controller.rb:19:in `response'
  app/controllers/crawler_controller.rb:21:in `response'
  app/controllers/crawler_controller.rb:19:in `response'
  app/controllers/crawler_controller.rb:21:in `response'
  app/controllers/crawler_controller.rb:19:in `response'

pretty strange huh?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

带刺的爱情 2024-11-25 21:23:06

尝试将您的方法从 response 重命名为其他名称。我认为 Rails 可能会将响应用于其他用途。

Try renaming your method from response to something else. I think response might be used by Rails for something else.

孤芳又自赏 2024-11-25 21:23:06

尝试将变量从 @request 重命名为其他名称。我认为 Rails 可能会将 @request 用于其他用途。

还可以尝试将您的操作从 response 重命名为其他内容。我认为 Rails 可能会将响应用于其他用途。

Try renaming your variable from @request to something else. I think @request might be used by Rails for something else.

Also try renaming your action from response to something else. I think response might be used by Rails for something else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文