Gerome John Pangan Gerome John Pangan - 4 months ago 21
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

post/index

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


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

Answer

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

Comments