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
posted on 2009-08-11 17:14
fl1429 阅读(639)
评论(0) 编辑 收藏 所属分类:
Rails