Search code examples
ruby-on-railsruby-on-rails-4turbolinks

Link in entire table row seems not to use turbolinks


Im referencing to Link entire table row?

I followed the instructions and now have a link in each table row:

<% @patients.each do |patient| %>
      <tr onclick="location.href='<%= patient_path(patient) %>'">
        <td><%= patient.name %></td>   

This generates for example such a link:

 <tr onclick="location.href='/patients/18'">

My problem is now that when i click on a link turbolink isnt used and it takes very long to reload the whole page! How do i have to change my code so that turbolinks is used? Thanks


Solution

  • Try any of these versions, turbolinks should pick up any regular link.

    <% @patients.each do |patient| %>
      <tr>
        <td><%= link_to patient.name, patient_path(patient) %></td>
      </tr>
    <% end %>
    
    <% @patients.each do |patient| %>
      <%= link_to patient_path(patient) do %>
        <tr>
          <td><%= patient.name %></td>
        </tr>
      <% end %>
    <% end %>
    
    <% @patients.each do |patient| %>
      <tr>
        <%= link_to patient_path(patient) do %>
          <td><%= patient.name %></td>
        <% end %>
      </tr>
    <% end %>