0

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

Community
  • 1
  • 1
John Smith
  • 6,105
  • 16
  • 58
  • 109

1 Answers1

1

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 %>
Thomas Klemm
  • 10,678
  • 1
  • 51
  • 54