48
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

Rails5でTurbolinksの挙動が変わってた。

今までのイベント

$(document).on 'page:before-change' , -> console.log 'page:before-change'
$(document).on 'page:fetch'         , -> console.log 'page:fetch'
$(document).on 'page:receive'       , -> console.log 'page:receive'
$(document).on 'page:change'        , -> console.log 'page:change'
$(document).on 'page:update'        , -> console.log 'page:update'
$(document).on 'page:load'          , -> console.log 'page:load'
$(document).on 'ready page:load'    , -> console.log 'ready and load'
$(document).ready                     -> console.log '$(document).ready in assets'
$(window).on 'load'                 , -> console.log '$(window).load in assets'

これでJSが発火してくれていたが、、、

Rails5でのイベント

# ページ切り替え時(初回ページも対象)
$(document).on 'turbolinks:load', -> console.log 'turbolinks:load'
# ページ切り替え時(初回ページは対象外)
$(document).on 'turbolinks:render', -> console.log 'turbolinks:render'
# ページ遷移前
$(document).on 'turbolinks:request-start', -> console.log 'turbolinks:request-start'

これで発火するように変わってた。
当面はこの二つだけ知っていれば問題ないかな。

あと、ページにキャッシュするページ数とかを設定できそうだけど、今の所はまだ未調査。
部分レンダリングすらまだ使ってない。

TurbolinksのGithubはこちら。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
48
Help us understand the problem. What are the problem?