目的
RailsでTurbolinksを有効にしてると、そのままではjQueryが有効にならないのでそれを解消する。
コード
readyを定義して、page:loadにバインドする。
application.js.coffee
#= require jquery
#= require jquery_ujs
#= require turbolinks
ready = ->
# smooth scroll to top
$(".navbar-brand").on 'click', (e) ->
e.preventDefault()
hash = this.hash
$('html, body').animate {
scrollTop: $(hash).offset().top
}, 300, ->
window.location.hash = hash
false
$(document).ready(ready)
$(document).on('page:load', ready)
おー、うごいたうごいた。
kossnocorp/jquery.turbolinks
こういうのもあるみたい。