【发布时间】:2014-11-11 20:04:16
【问题描述】:
我正在使用fullcalendar 在我的 Rails 应用程序上显示事件。工作正常。现在我希望事件在数据库中更新拖放操作。为此,我使用eventDrop 方法和基于this 的ajax 调用答案:
eventDrop: function(event, delta, revertFunc) {
update_source = update_prefix + event.user_id + "/appointments/" + event.id;
$.ajax({
type: "POST",
dataType: "script",
url: update_source,
contentType: 'application/json',
data: JSON.stringify({ resource:{start:event.start, end: event.end}, _method:'put' })
}).done(function( msg )
{
alert( "Data Saved: " + msg );
});
}
这是控制器上的更新方法:
def update
@appointment.update(appointment_params)
if @appointment.save
respond_to do |format|
format.js
end
else
render js: "alert('Please include phone number');"
end
end
这些是 rake 路线上的路线:
PATCH (/:locale)/companies/:company_id/users/:user_id/appointments/:id(.:format) appointments#update
PUT (/:locale)/companies/:company_id/users/:user_id/appointments/:id(.:format) appointments#update
DELETE (/:locale)/companies/:company_id/users/:user_id/appointments/:id(.:format) appointments#destroy
但是我不断收到以下错误:
ActionController::RoutingError (No route matches [POST] "/es/companies/1/users/50/appointments/140"):
以防万一;实际上,数据库中有一个 id 为 140 的约会属于属于公司 1 的用户 50。
谢谢
【问题讨论】:
标签: javascript ruby-on-rails ajax fullcalendar