简体   繁体   English

Ajax调用上的RoutingError以更新fullcalendar事件

[英]RoutingError on ajax call to update fullcalendar event

i'm using fullcalendar to show events on my rails application. 我正在使用fullcalendar在我的rails应用程序上显示事件。 Works fine. 工作正常。 Now i want the events to update in the database on drag and drop actions. 现在,我希望通过拖放操作在数据库中更新事件。 For that i'm using eventDrop method and an ajax call based on this answer: 为此,我正在使用eventDrop方法和基于答案的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 );
            });
        }

This is update method on the controller: 这是控制器上的更新方法:

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

And these are the routes on rake routes: 这些是耙路线上的路线:

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

However i keep getting the following Error: 但是我一直收到以下错误:

ActionController::RoutingError (No route matches [POST] "/es/companies/1/users/50/appointments/140"):

Just in case; 以防万一; there is actually an appointment with id 140 belonging to a user 50 belonging to company 1 in the database. 实际上在数据库中有一个ID 140属于用户50的约会,该用户50属于公司1。

Thanks 谢谢

Changing your ajax request to PUT or PATCH will solve your issue, however I am not sure this is the intention. 将您的Ajax请求更改为PUTPATCH将解决您的问题,但是我不确定这是否有此意图。 I mean: 我的意思是:

        $.ajax({
            type: "PATCH",
            dataType: "script",
            url: update_source,
            contentType: 'application/json',
            data: { resource:{start:event.start, end: event.end} }
        }).done(function( msg )
        {
            alert( "Data Saved: " + msg );
        });

It will call update action. 它将调用update操作。 Also, you do not need JSON.stringify , just pass data {...} . 另外,您不需要JSON.stringify ,只需传递数据{...}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM