Rails在一个请求上接收重复请求

时间:2017-01-05 01:07:15

标签: ruby-on-rails

我的路线如下:

Rails.application.routes.draw do
  get 'courses' => 'application#index'
  get 'check_db' => 'application#check_db'

  root 'application#index'
end

我的application#check_db

def check_db
  p "test"
  redirect_to root_path
end

当我在浏览器上访问/check_db时(在Chrome和Safari中都尝试过),如果工作正常,则应GET "/check_db"然后GET "/"。但实际上,日志显示有四个请求,上述模式重复两次(即GET "/check_db"GET "/"GET "/check_db"GET "/")。我的application#index中绝对没有任何代码可以执行任何其他重定向。那为什么会这样?

上述情况大多数时间都会发生。但是,偶尔会按预期工作。我没有在过渡期间更改代码。

如果感兴趣,则将整个日志粘贴在下面:

Started GET "/check_db" for ::1 at 2017-01-04 17:05:06 -0800
Processing by ApplicationController#check_db as HTML
"test"
Redirected to http://localhost:3000/
Completed 302 Found in 1ms


Started GET "/" for ::1 at 2017-01-04 17:05:06 -0800
Processing by ApplicationController#index as HTML
  Rendering application/index.html.erb within layouts/application
[MongoDB query log]
  Rendered application/index.html.erb within layouts/application (3.4ms)
Completed 200 OK in 18ms (Views: 16.4ms)


Started GET "/check_db" for ::1 at 2017-01-04 17:05:07 -0800
Processing by ApplicationController#check_db as HTML
"test"
Redirected to http://localhost:3000/
Completed 302 Found in 8ms


Started GET "/" for ::1 at 2017-01-04 17:05:07 -0800
Processing by ApplicationController#index as HTML
  Rendering application/index.html.erb within layouts/application
[MongoDB query log]
  Rendered application/index.html.erb within layouts/application (4.1ms)
Completed 200 OK in 17ms (Views: 15.0ms)

0 个答案:

没有答案