Sinatra haml page called twice

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 

I see in the log that the page above is constantly being called twice:

 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 

I have some problems. Why is this happening?

+4
source share
2 answers

I switched to the Puma server installed on Webrick due to similar problems. Unfortunately, I have lost sample code with this problem. In any case, if you have such problems, please find out what brouser does:

  • The Developers> Network tool (tab) will show the exact source of the request, if it exists
  • Try narrowing this problem / problem by reducing the code. Comment on all Java scripts, change the contents of the page to "Hello Wold" and watch that the problem is still happening.
  • Share your code :)

Sorry for posting here, I don’t know how to publish this as an addition to your qestion.

+2
source

This is a hack, but if you really need to get it to run the code only once: Create a global boolean variable. in the route, wrap everything in a conditional boolean. if false, set it true, run your code and set it again.

0
source

Source: https://habr.com/ru/post/1443487/


All Articles