Skip to content

Instantly share code, notes, and snippets.

@iboard
Created June 16, 2013 12:45
Show Gist options
  • Save iboard/5791932 to your computer and use it in GitHub Desktop.
Save iboard/5791932 to your computer and use it in GitHub Desktop.
Handle click on a table-row with Rails4 and coffeescript
# WORKS THE FIRST TIME BUT FAILES WHEN RETURNING TO THE PAGE UNLESS RELOADING
jQuery ->
$('.clickable-row td').click ->
target_id = $(this).parent().attr('id').replace /row-id-/,''
document.location = "/controller_xy/#{target_id}/edit"
# WORKS FINE EVERY TIME
jQuery ->
$(document).on( 'click', '.clickable-row td', ->
table_row = $(this).parent()
target_id = table_row.attr('id').replace /row-id-/, ''
document.location = "/players/#{target_id}/edit"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment