【问题标题】:RoutingError on ajax call to update fullcalendar eventajax 调用上的 RoutingError 以更新 fullcalendar 事件
【发布时间】: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


    【解决方案1】:

    将您的 ajax 请求更改为 PUTPATCH 将解决您的问题,但我不确定这是否是意图。我的意思是:

            $.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 );
            });
    

    它将调用update 操作。另外,您不需要JSON.stringify,只需传递数据{...}

    【讨论】:

    • 成功了!谢谢@blelump
    • @ntonnelier 你能指导我完成同样的任务吗??
    • 嗨@AnitaShalu,对我来说,问题是将操作从POST更改为PATCH。如果可行,您应该尝试一下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多