2016-10-16 7 views
0

これは私のサイドバーには表示されないようです。私はそれがページをリロードすると動作すると思われるので、レール4のTurbolinksと関係があると思う。どのようにこれを動作させるためにこれを変更する上で任意のアイデア?Rails 4ターボリンクコーヒースクリプトがロードされない

jQuery -> 
    category = $('#subject_category').html() 
    $('#subject_product').change -> 
    product = $('#subject_product :selected').text() 
    escaped_product = product.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1') 
    options = $(category).filter("optgroup[label='#{escaped_product}']").html() 
    if options 
     $('#subject_category').html(options) 
     $('#subject_category').parent().show() 
    else 
     $('#subject_category').empty() 
     $('#subject_category').parent().hide() 

$ -> 
    category = $('#sidebar .category_select').html() 
    options = $(category).filter("optgroup[label='Car']").html() 
    if options 
    $('#sidebar .category_select').html(options) 
    $('#sidebar .category_select').parent().show() 
    else 
    $('#sidebar .category_select').empty() 
    $('#sidebar .category_select').parent().hide() 
+0

私の問題は、コーヒースクリプトの構文ですが、他の投稿が私の要求に対処しているかどうかはわかりません。これらはonloadイベントではありませんので、 – user2012677

+0

'$ - >'は 'jQuery - >'の短縮形です。これは 'document ready'のショートカットです。この記事では、 'document ready'とturbolinksで何が違うのかを説明しています。私はそれがあなたの問題だと確信しています。 – slowjack2k

+0

だから、 '$ - >'を '$(document).on" turbolinks:load "、 - >'に置き換えるべきですか? 'jQuery - >'のショートカットは何ですか? 'jQuery - >'を '$(document).on" turbolinks:load "、 - >'に置き換えるべきですか? – user2012677

答えて

0
$(document).on "turbolinks:load", -> 
alert "page has loaded!" 

宝石もあります - jquery.turbolinks gem。念のため。 4.2以上で動作します。下に私は知らないだろう。

+0

'jQuery - >'と '$ - >'を '$(document).on" turbolinks:load "、 - >'に置き換えるべきですか? – user2012677

関連する問題