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
ImpostorIsAsking
951 gold badge7 silver badges31 bronze badges
1 Answer 1
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
answered Aug 4, 2016 at 0:57
Pradeep Sapkota
2,0921 gold badge19 silver badges32 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
ImpostorIsAsking
hi there pradeep sapkota your very active here. my i ask where can learn more in JS?
Pradeep Sapkota
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.
ImpostorIsAsking
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 :*
Pradeep Sapkota
Now how did it reached.
lang-js
$(document).on