【发布时间】:2012-10-22 07:59:41
【问题描述】:
get '/test' do
session[:my_session_id] = generate_random_id()
puts 'begin haml debug'
haml :"static/haml_page", :locals=>{:session_id => session[:my_session_id]}
end
我在日志中看到上面的页面经常被调用两次:
begin haml debug
127.0.0.1 - - [02/Nov/2012 00:00:01] "GET / HTTP/1.1" 200 4317 1.5421
127.0.0.1 - - [02/Nov/2012 00:00:01] "GET /js/base/jquery.pjax.002902.js HTTP/1.1" 304 - 0.0234
[2012-11-02 00:00:01] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
127.0.0.1 - - [02/Nov/2012 00:00:01] "GET /css/docs.002902.css HTTP/1.1" 200 165 0.1086
.................................
begin haml debug
127.0.0.1 - - [02/Nov/2012 00:00:04] "GET / HTTP/1.1" 200 4317 1.9288
这让我有一些问题。为什么会这样?
【问题讨论】:
-
当您尝试使用其他浏览器或 curl 时是否会发生这种情况?例如
curl http://localhost:9292 -
不,它没有! Chrome 请求它两次。为什么?
-
您的路线显示
get '/test',但您的日志显示GET /。您是否将示例与真实的示例进行了更改? -
是的,这只是一个错字。 Opera 不会两次请求页面。
-
如果 Chrome 请求了两次,请尝试其他 Webkit 浏览器,例如 Safari,看看它是否也在其中。我不知道为什么 Chrome 会这样做,但至少你正在缩小范围。
标签: ruby sinatra haml rack webrick