Every link_to on my rails 4 application is being called twice
If you would like your app to still make use of Turbolinks then "Opting out of Turbolinks" on the code that is giving you problems is the way to go; just add data-no-turbolink
.
I was having problems with using Bootstrap 3 and adding that fixed it. For example;
<li class="list-group-item" data-no-turbolink>
<%= link_to download_path(item) do %>
<button type="button" class="btn btn-success">Download</button>
<% end %>
</li>
I was also facing same issue in Rails 5, here is my machine Details-
$ rails -v
Rails 5.2.2
$ ruby -v
ruby 2.6.1p33
Whenever I was clicking on a link, whole controller was being call twice.
I tried accepted answer but does not worked for me,
so I just set turbolinks: false
as below-
Link is: <%= link_to("Demo link", "/abc/pqr/#{current_user.id}", data: { turbolinks: false } ) %>
This worked for me, Thanks for above hints!!!
I actually managed to solve this on my own. There's a default gem that is installed with rails 4.0, it is called Turbolinks*.
For some reason, the javascript used in this gem* was causing the doubled requests on my server. That's why only GET requests were behaving like this, and POST requests were normal.
I still don't fully understand why gem* causes that, but after I removed the following line from my application.js
file, the doubled requests stopped.
=// require turbolinks