我在这里不知所措。我有一个相当简单的事情,但似乎遇到了很多问题。我在工作中有直接的网络爬虫。人们发布请求并将其发送到队列。如果他们想查询队列中的最新信息:路由是
127.0.0.1:8080/requests/id/1.json
响应是动作(def) CrawlerController是控制器。 请求是模型。
继承路线:(虽然我认为不相关)
match 'requests/id/:id' => 'crawler#response'
这是控制器中的def:
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'
很奇怪啊?
答案 0 :(得分:3)
尝试将您的方法从response
重命名为其他内容。我认为Rails可能会使用response
来做其他事情。
答案 1 :(得分:1)
尝试将变量从@request
重命名为其他内容。我认为Rails可能会使用@request
来做其他事情。
还可以尝试将您的操作从response
重命名为其他内容。我认为Rails可能会使用response
来做其他事情。