I'm trying a solution to resolve a duplication of requests happening in my Ruby on Rails 6 project deployed to Heroku.
This seems to occur when those anchors with hyperlinks are used, so it loads 2x.
As a result, it ends up generating duplicate logs because it also calls the controller (GET -> Controller -> Model -> View).
Below are some logs that prove the duplicate request:
caio-agiani in ~ via ⬢ v14.21.3 took 10m 37s ❯ heroku logs -a levante-web -t | grep 2804:7f0:b8c2:13f:8755:4a1e:74b8:x735,172.71.10.17
2024-03-31T02:32:36.318790+00:00 heroku[router]: at=info method=GET path="/levante/search?query=caioagiani" host=app request_id=3e84b5d5-b478-41aa-b1e8-218838f37ca1 fwd="2804:7f0:b8c2:13f:8755:4a1e:74b8:x735,172.71.10.17" dyno=web.1 connect=0ms service=426ms status=200 bytes=12075 protocol=https
2024-03-31T02:32:57.648033+00:00 heroku[router]: at=info method=GET path="/levante/search?query=caioagiani" host=app request_id=f17c6635-3541-4153-8283-3811659ff00a fwd="2804:7f0:b8c2:13f:8755:4a1e:74b8:x735,172.71.10.17" dyno=web.1 connect=0ms service=330ms status=200 bytes=12077 protocol=https
2024-03-31T02:33:01.813927+00:00 heroku[router]: at=info method=GET path="/levante/shop/index" host=app request_id=cc5dd643-41c3-45e9-bffa-a73ed617d0b0 fwd="2804:7f0:b8c2:13f:8755:4a1e:74b8:x735,172.71.10.17" dyno=web.1 connect=0ms service=42ms status=200 bytes=25575 protocol=https
2024-03-31T02:33:02.145246+00:00 heroku[router]: at=info method=GET path="/levante/shop/index" host=app request_id=7bdfadad-273e-4b8a-ab88-4f0422ececaf fwd="2804:7f0:b8c2:13f:8755:4a1e:74b8:x735,172.71.10.17" dyno=web.1 connect=0ms service=39ms status=200 bytes=25564 protocol=https
PS: Could this be linked to Turbolink/Load or some internal Rails script like ujs? I have evidence that yes, as I have another application in production using exactly the same setup, however, 1 uses the conventional rails native import scripts and css template (javascript_include_tag, javascript_pack_tag, stylesheet_pack_tag) and the other uses simple HTML meta tags
Well, this was actually due to turbolinks, basically there was the section to inject the data-turbolinks-track
, reload
[schreenshot].
This problem also did not appear locally because the snippet of this pixel script had a check for the production
environment.
It is also possible to keep the data-turbolinks-track reload, but you need to add data-turbolinks=false
in the anchor element
= link_to "Comprar", levante_checkout_offer_path(offer), class: "btn button-primary", data: { turbolinks: "false" }
$(document).on("turbolinks:load", () => {
$("a").attr("data-turbolinks", "false");
});