【发布时间】:2015-11-12 18:13:59
【问题描述】:
我正在向 Rails 发出 ajax 请求,将数据传递给 id。
这里是ajax
function delete_availability(id) {
var id = id;
$.ajax({
type: "DELETE",
url: "/events/" + id,
statusCode: {
200: function() {
//alert("200");
},
202: function() {
//alert("202");
}
},
success: function(data) {
console.log('availability deleted');
},
error: function(xhr) {
alert("The error code is: " + xhr.statusText);
}
});
}
我的破坏行动
def destroy
@event = Event.find_by(params[:id]);
respond_to do |format|
if @event.destroy
format.json {
render json: {}
}
end
end
end
我的事件模型中没有任何内容
class Event < ActiveRecord::Base
end
问题是即使 rails 接收到正确的 id,当它去销毁时,它也会更改 id 并销毁下一个。
这是 rails 日志:
Processing by EventsController#destroy as */*
Parameters: {"id"=>"66"}
Event Load (0.1ms) SELECT "events".* FROM "events" WHERE (66) LIMIT 1
(0.0ms) begin transaction
SQL (0.2ms) DELETE FROM "events" WHERE "events"."id" = ? [["id", 65]]
(2.4ms) commit transaction
Completed 200 OK in 6ms (Views: 0.1ms | ActiveRecord: 2.8ms)
有人知道为什么吗?
【问题讨论】:
-
请发布您的活动模型。
-
里面什么都没有。只是类声明,无论如何更新我的帖子
-
将
find_by更改为find。
标签: ruby-on-rails ruby ajax ruby-on-rails-3