2016-09-13 9 views
7

私は自分のレールプロジェクトでコーヒースクリプトを使用していますが、問題は、ページをレンダリングするときにページをロード(リフレッシュ)するときにのみ機能し、ページビューの変更でも機能するはずです。ここコーヒースクリプトはページ上で発火しませんが、ページの読み込み時に機能します。 [Rails 5]

は、私が使用していたスクリプトです:

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 

答えて

4

あなたは"turoblinks:load"

ready = -> 
    $('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 


$(document).on('turbolinks:load', ready) 
を試すことができます
関連する問題