May be such problem is not new, but I didn't find anything similar. I have such jQuery code:
$.ajax({
url : ('/people/'+id),
type : 'DELETE',
dataType : 'json',
success : function(e) {
table.getItems(currentPage);
}
});
My Rails controller looks like this:
def destroy
@person = Person.find(params[:id])
@person.destroy
respond_to do |format|
format.html { redirect_to(people_url) }
format.json { render :json => @person, :status => :ok }
end
end
This is working.
But when I use the following (as generated by standard), the success
callback doesn't get called:
def destroy
@person = Person.find(params[:id])
@person.destroy
respond_to do |format|
format.html { redirect_to(people_url) }
format.json { head :ok }
end
end
Tested under rails 3.0.3
, jQuery 1.4.2
and Firefox 3.6.13
.
Firebug says, that query is fired and returns 200 OK in both cases, item is deleted in both cases too. But in second case the callback is not called.
Is there a significant difference in REST, and is there a way to utilize jQuery by using the scaffolded controller?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…