I just watch a vid from http://railsforzombiestwo.codeschool.com/levels/5 which the vid show a tutorial on how to make a delete link fade out with Ajax (from 8:40 - 11:00). i try to do it but its failed.. no fade out and disappear / page not refreshed. after i click the delete button, i've to refresh the page manually to make it disappear. here is my code :
controller:
def destroy
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])
@comment.destroy
respond_to do |format|
format.html {redirect_to post_path}
format.js
end
end
views : views/_comment.html.erb
<% if current_user && current_user.id == @post.user_id %>
<p>
<%= link_to 'Delete', [comment.post, comment],
method: :delete,
remote: true,
class: "button" %>
</p>
<% end %>
</div>
destroy.js.erb
$('#<%= dom_id(@comment) %>').fadeOut();
from the codeschool(railsforzombiestwo), it shows that only 3 step needed. I try and its not working for me. Almost 2 month of learning rails with no basic programming ^^'. Help me??
Add id to this div element <div class="comment clearfix">
<div class="comment clearfix" id="comment_<%= comment.id %>">
Then in destroy.js.erb do this
$("#comment_<%= @comment.id %>").fadeOut();
Hope that helps!
Try this
<div class="comment clearfix" id="comment-<%= comment.id %>">
<div class="comment_content">
<p class="comment_name">
<strong><%= comment.name %></strong>
</p>
<p class="comment_body"><%= comment.body %></p>
<p class="comment_time"><%= time_ago_in_words(comment.created_at) %> ago</p>
</div>
<% if current_user && current_user.id == @post.user_id %>
<p> <%= link_to 'Delete', [comment.post, comment], method: :delete, remote: true, class: "button" %> </p>
<% end %>
</div>
</div>
</div>
$("#comment-<%= @comment.id %>").fadeOut();