every time i use the remove method when deleting object via javascripts it does not work.
my destroy.js code is as follows.
$("#<%= dom_id(@comment) %>").remove();
$('#comment-count-<%= @parent.id %>').html("<%= pluralize(@parent.comments.count,'comment')%>");
the pluralize works just fine
my _comment.html.erb is as follows
<%= div_for comment do %>
<% if comment.user.profile.icon.exists? %>
<%= image_tag comment.user.profile.icon.url(:small), :alt => comment.user.name, :class => "avatar tip", :title => comment.user.name %>
<% else %>
<%= image_tag comment.user.gender == 'Female' ? 'missing_woman.png' : 'missing_thumb.png', :alt => comment.user.name, :class => "avatar tip", :title => comment.user.name %>
<% end %>
<div class="comment-container">
<span><%= link_to comment.user.name, comment.user.profile, :class => "profile-link-small" %></span> <%= comment.comment%>
<div><span style="color:#888;"><%= formatted_time(comment.created_at) %></span> –– <span class="rank"><%= comment.user.level %></span>
<% if can? :update, comment%> |
<span class="del"><%= link_to "Delete", comment, :confirm => "Are you sure you want to delete this comment?", :method => :delete, :remote => true %></span>
<% else %>
<span class="dialog_link">Delete</span>
<% end %>
</div>
</div>
<div class="clear"></div>
<% end %>
It use to work before but after i updated to rails rc5 it storped
Your jQuery says this:
But your ERB says this:
Your
div_forshould produce HTML something like this:Assuming that
commentis a Comment object with id 11. Thendom_idon the same comment would producecomment_11and that’s all good.However, you’re using
@comment(an instance variable) to generate the DOM ID for the jQueryremovecall but the local variablecommentfor the HTML. I’d guess thatcommentis the right one and you’re feeding aniltodom_id, the result is that the IDs don’t match and your jQuery does nothing useful.