4

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

asked Aug 4, 2016 at 0:53
2
  • 1
    Typo? $(document).on Commented Aug 4, 2016 at 0:55
  • thanks man i'm new in JS and i really want to learn Commented Aug 4, 2016 at 0:57

1 Answer 1

4

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

Anna S
1571 silver badge9 bronze badges
answered Aug 4, 2016 at 0:57
Sign up to request clarification or add additional context in comments.

4 Comments

hi there pradeep sapkota your very active here. my i ask where can learn more in JS?
Actually I'm not a Academically studied programmer. Resource in internet are fine. If you found answer right for you please accept it and vote. That will keep me helping. Thank you.
vote is for 15 reputation only and i have 10 in accept 7 mins cooldown before i accept dont you worry i will accept your answer your very helpfull thanks :*
Now how did it reached.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.