SyntaxError:[stdin]:6:2:意外{

时间:2016-08-04 00:53:39

标签: javascript ruby-on-rails

我正在尝试向我的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"

然后,当我想尝试我的评论链接,如果它的工作此错误给我 enter image description here

1 个答案:

答案 0 :(得分:2)

您的咖啡脚本中存在语法错误

这样做:

$(document).on "page:change", ->
  $('#comment-link').click ->
    alert "clicked"

而不是:

${document}.on "page:change", ->
$('#comment-link').click ->
    alert "clicked"

请记住,缩写是编写咖啡脚本时最重要的