Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 701
wiwit Avatar asked Oct 28 '25 13:10

wiwit


1 Answers

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, indentation is most important while writing coffee script

like image 199
Pradeep Sapkota Avatar answered Oct 31 '25 01:10

Pradeep Sapkota