Reputation: 73
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
Upvotes: 4
Views: 1275
Reputation: 2082
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
Upvotes: 4