How do I make this snippet of CoffeeScript TurboLi

2019-07-26 09:52发布

I have the following:

$ ->
    $('[data-provider="summernote"]').each ->
      $(this).summernote
        height: 300

And this works, however, I would like to make it TurboLinks 5 friendly.

So I tried the following:

$ ->
  ready = ->
    $('data-provider="summernote"]').each ->
      $(this).summernote
        height: 300

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

But I keep getting this error:

Uncaught ReferenceError: ready is not defined

How do I fix this so that I make the original snippet TL-5 friendly?

Edit 1

By the way, I am doing this in my jobs.coffee file, which I know is being included in my asset-pipeline. So that's not it.

1条回答
叼着烟拽天下
2楼-- · 2019-07-26 10:13

In Rails 5 (Turbolinks 5), turbolinks:load. Also, you don't need to wrap your event handlers into the "document ready".

Rewrite your code to this:

ready = ->
  $('data-provider="summernote"]').each ->
    $(this).summernote(height: 300)

$(document).ready(ready)
$(document).on('turbolinks:load', ready)
查看更多
登录 后发表回答