我正在尝试向我的rails应用添加一些Javascript。我想在帖子区隐藏我的评论
交/索引
<%= link_to "Comment", "#", id: "comment-link " %>
<section id="comment-section">
<%= render 'commenters/newsfeedcomment', obj: post %>
<% if current_user == post.user %>
<h6 align="right"><%= link_to 'Edit', edit_post_path(post) %></h6>
<h6 align="right"><%= link_to 'Delete', { :id => post ,:controller => 'posts',:action => 'destroy'} %></h6>
<% end %>
</section>
CSS
#comment-section{
display: none;
}
commenters.coffee
${document}.on "page:change", ->
$('#comment-link').click ->
alert "clicked"
答案 0 :(得分:2)
您的咖啡脚本中存在语法错误
这样做:
$(document).on "page:change", ->
$('#comment-link').click ->
alert "clicked"
而不是:
${document}.on "page:change", ->
$('#comment-link').click ->
alert "clicked"
请记住,缩写是编写咖啡脚本时最重要的