Making a table row into a link in Rails

As Robin said, that’s invalid HTML. You probably shouldn’t do that.

I personally would put an onclick event on the tr using jQuery. The tr element would look like this:

<tr data-link="<%= edit_scout_path(scout) %>">
   ...
</tr>

And then the associated JavaScript (placed in a file such as app/assets/javascripts/scouts.js) would be something like this:

$("tr[data-link]").click(function() {
  window.location = $(this).data("link")
})

This would make all tr elements that have a data-link attribute act as if they were URLs in the most unobtrusive way I can think possible.

Leave a Comment