随笔-167  评论-65  文章-0  trackbacks-0
link_to_remote 是ajax方法的destroy方法,主要是view里的id要是不同的值 和 controller 中的page.remove 方法
使用方法:

view:
<div   id="activity_<%=activity.id%>" class="blog_item clearfix">
..........
  <%= link_to_remote image_tag("/images/icons/network/close.gif"),
    :url  => {:controller=>'activities', :action =>'destroy',:id=>activity.id },
    :method => :delete,
    :confirm => %(确认删除更新?)
  %>
</div>

controller:

 def destroy
    @activity.destroy
  #  flash[:notice] = "状态已删除"
    respond_to do |format|
      format.html { redirect_to :back }
      format.xml  { head :ok }
      format.js do
        render :update do |page|
          page.remove "activity_#{@activity.id}"
        end
      end
    end
  end

ref:
http://scottmotte.com/archives/62.html



write by feng
posted on 2009-08-11 17:14 fl1429 阅读(632) 评论(0)  编辑  收藏 所属分类: Rails

只有注册用户登录后才能发表评论。


网站导航:
 
已访问数:
free counters