Ruby 应用程序响应直到堆栈太深
我在这里不知所措。我有一个相当简单的事情,但似乎遇到了很多问题。我正在开发直接的网络爬虫。人们发布请求并将其发送到队列中。如果他们想查询队列中有什么:路由是
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将您的方法从
response
重命名为其他名称。我认为 Rails 可能会将响应用于其他用途。Try renaming your method from
response
to something else. I thinkresponse
might be used by Rails for something else.尝试将变量从
@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 thinkresponse
might be used by Rails for something else.