Tôi đang sử dụng kịch bản cà phê trong dự án đường ray của mình, nhưng vấn đề là nó chỉ hoạt động khi tôi tải (làm mới) trang thay vì khi trang hiển thị, nó cũng sẽ hoạt động trên thay đổi chế độ xem trang.Coffee Script không kích hoạt thay đổi trang, nhưng hoạt động khi tải trang. [Rails 5]
đây là kịch bản tôi đang sử dụng:
facebook.js.coffee
jQuery ->
$('body').prepend('<div id="fb-root"></div>')
$.ajax
url: "#{window.location.protocol}//connect.facebook.net/en_US/all.js"
dataType: 'script'
cache: true
window.fbAsyncInit = ->
FB.init(appId: env["app_id"], cookie: true)
$('#sign_in').click (e) ->
e.preventDefault()
FB.login (response) ->
window.location = '/auth/facebook/callback' if response.authResponse
$('#sign_out').click (e) ->
FB.getLoginStatus (response) ->
FB.logout() if response.authResponse
true