Question

$ ->
  $("li").click ->
    console.debug "item clicked"

  $("input").change ->
    console.debug "text changed"

How to optimize the code to make it work efficiently with turbolinks?

Was it helpful?

Solution

Although your code seems correct, you may wish to alter it a little (for turbolinks & syntax efficiency):

load = ->
  $(document).on "click", "li", ->
    console.debug "item clicked"

  $(document).on "change", "input", ->
    console.debug "text changed"

$(document).ready load
$(document).on "page:load", load

If you're receiving an error, it's likely be cause of something else or some strange formatting issue with

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top