1

Attempting to make table rows clickable links to "edit" pages. I've implemented this on other projects with no issues, but on this project cannot get it to function.

I'm using the method mentioned here: Making a table row into a link in Rails

This alone has worked in the past but in this project was not. Since we are using Turbolink's I've attempting to use the method mentioned here as well: Rails 4 turbo-link prevents jQuery scripts from working

There is absolutely no response and no errors when clicking a row. Heres my code

in views/students/index.html.erb:

<tbody>
<% @students.each do |student| %>
  <tr data-link = "<%= edit_student_path(student) %>">
    [… row info …]
  </tr>
<% end %>

in assets/javascripts/students.js

$(document).on('turbolinks:load', function () {
  $("tr[data-link]").click(function() {
    window.location = this.data("link")
  })
})

I can see in developer view that <%= edit_student_path(student) %> is generating the correct link. In desperation I also tried linking the view to the javascript as shown here: how to load a Javascript file to rails html erb

That did not fix anything. The assets manifest and application.js appear to be correct as well. Any suggestions on what might be inhibiting the click event from triggering would be greatly appreciated.

Community
  • 1
  • 1
El_Wray85
  • 11
  • 2
  • Can you add a `console.log('whatever')` inside the click event, so we can see if the click event is firing at all? Trying to determine *where* the issue is actually occurring. – jeffdill2 May 19 '17 at 22:01
  • In fact, add a few. One in `students.js` so we can see if the JS is loading at all. One​ immediately inside the `$(document).on('turbolinks:load', ...`, so we can see if that's loading and one inside the click event to see if that's firing. That'll give us a very good starting point to figure out where the breakdown is occurring. – jeffdill2 May 19 '17 at 22:07

0 Answers0