Gerome John Pangan Gerome John Pangan - 1 year ago 172
Javascript Question

SyntaxError: [stdin]:6:2: unexpected {

I'm trying to add some Javascript to my rails apps. i want to hide my comment in the post area


<%= 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 %>


display: none;


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

then when i want to try my Comment link if its working this error give me
enter image description here

Answer Source

You have syntax error in your coffee script

Do this:

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

Instead of:

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

Remember Intendention is most important while writing coffee script

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download