Making a table row into a link in Rails

后端 未结 5 1072
刺人心
刺人心 2020-11-30 02:07

I am trying to make a row in a table link to the edit page. I know the links are being created, because I can print them out. I am close, but am missing something importan

5条回答
  •  粉色の甜心
    2020-11-30 02:37

    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:

    
       ...
    
    

    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.

提交回复
热议问题