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_开发者_Python百科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:
$("#<%= dom_id(@comment) %>").remove();
//-------------^
But your ERB says this:
<%= div_for comment do %>
Your div_for
should produce HTML something like this:
<div id="comment_11">
<!-- ... -->
<div>
Assuming that comment
is a Comment object with id 11. Then dom_id
on the same comment would produce comment_11
and that's all good.
However, you're using @comment
(an instance variable) to generate the DOM ID for the jQuery remove
call but the local variable comment
for the HTML. I'd guess that comment
is the right one and you're feeding a nil
to dom_id
, the result is that the IDs don't match and your jQuery does nothing useful.
精彩评论