2008-02-26
使用link_to_remote制作ajax时遇到的问题
关键字: link_to_remote, rjs
controller code:
render code:
_comments code:
delete_comment.rjs code:
代码有点长~
情况是_comments局部模板在删除@comments内最后一个记录时会刷新一次,看到了ajax效果,删除倒数第2,第3个时,页面无反应...
救助...
看看是不是link_to_remote的参数使用上有问题...
谢谢!
def delete_comment
if request.delete?
@comment = Comment.find params[:c_id]
@comment.destroy
blog = Blog.find params[:id]
@comments = blog.comments(true)
end
end
render code:
<div id="comments"> <%= render :partial=>"comments", :object=>@comments %> </div>
_comments code:
<p>
You have <%=pluralize(comments.count, "comment") %> :
<ul>
<% for c in comments %>
<%= debug c %>
<li>
<%= c.name %>
<p><%= c.context %></p>
<%= link_to_remote :delete, :method=>:delete, :url=>{:action=>"delete_comment", :c_id=>c.id, :id=>@blog.id} %>
</li>
<% end %>
</ul>
</p>
delete_comment.rjs code:
page.replace_html("comments", :partial=>"comments", :object=>@comments)
代码有点长~
情况是_comments局部模板在删除@comments内最后一个记录时会刷新一次,看到了ajax效果,删除倒数第2,第3个时,页面无反应...
救助...
看看是不是link_to_remote的参数使用上有问题...
谢谢!
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则







评论排行榜