论坛首页 编程语言技术论坛

使用link_to_remote制作ajax时遇到的问题

浏览 2128 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-02-26  
controller code:
  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的参数使用上有问题...
谢谢!
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics