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 сообщает, что запрос запускается и возвращает 200 OK в обоих случаях, элемент также удаляется в обоих случаях. Но во втором случае обратный вызов не вызывается.
Есть ли существенная разница в REST и есть ли способ использовать jQuery с помощью встроенного контроллера?