2017-04-19 53 views
0

这里5触发事件是我的咖啡脚本turbolinks轨工作不

$(document).on "turbolinks:load", -> 
    $('#comments-link').click -> 
    $('#comments-section').toggle() 

这里是我的.scss文件

#comments-section{ 
display: none; 
} 

她是HTML文件

<%= link_to 'Comments','#', id: "comments-link"%> 

<div id="comments-section"> 
    <%= render @recipe.comments %> 
</div> 

当我点击在链接上,没有任何反应。 在Web控制台中,代码无任何错误。 任何建议

回答

1

好吧,我想通了,我不得不preventDefault()方法

$('#comments-link').click (e)-> 
    e.preventDefault() 
1

为了得到这个Rails的5工作,你需要添加的宝石:

宝石“jQuery的轨道” ,'4.3.1'

然后在'app/assets/javascripts/application.js'中,需要添加下面的第一行(其他3行已经在该文件中)需要jquery:

//= require jquery 
    //= require rails-ujs 
    //= require turbolinks 
    //= require_tree .