javascript(jquery-rails)在rails 3.1.rc5中无法正常工作
每次我通过javascripts删除对象时使用remove方法都不起作用。
我的destroy.js代码如下。
$("#").remove(); $('#comment-count-').html("");
复数就可以了
我的_comment.html.erb如下
comment.user.name, :class => "avatar tip", :title => comment.user.name %> comment.user.name, :class => "avatar tip", :title => comment.user.name %> "profile-link-small" %> –– | "Are you sure you want to delete this comment?", :method => :delete, :remote => true %> Delete
它用于工作之前,但在我更新到rails rc5之后它就会存在
你的jQuery说:
$("#<%= dom_id(@comment) %>").remove(); //-------------^
但你的再培训局说:
<%= div_for comment do %>
你的div_for
应该产生这样的HTML:
假设comment
是一个id为11的Comment对象。那么同一条评论的dom_id
会产生comment_11
,这一切都很好。
但是,您使用@comment
(实例变量)为jQuery remove
调用生成DOM ID,但为HTML生成局部变量comment
。 我猜这个comment
是正确的,你给dom_id
提供了一个nil
,结果是ID不匹配,你的jQuery没有任何用处。