I'm currently facing an issue with integrating FullCalendar into my rails application. Specifically, I am encountering difficulties with saving after performing drag-and-drop actions.
Within my application, I have two models - Event and Workout. The Event model includes a reference to the Workout model.
While I am able to successfully display and save events using FullCalendar, I noticed that when I drag and drop events and then refresh the page, the events revert back to their original time slots.
The console output indicates:
Couldn't find Event with 'id'=update.
Events created and saved through a form are properly displayed and saved on the calendar. The problem arises only when attempting to drag-and-drop events.
Below is the implementation in my Event controller:
class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!
# Controller actions for index, show, new, edit, create, update, destroy...
end
In my `application.js` file which governs the calendar functionality:
$(document).on('turbolinks:load', function() {
$('#calendar').fullCalendar({
editable: true,
events: '/events.json',
eventDrop: function(event, delta) {
$.ajax({
type: "PUT",
url: '/events/update',
dataType: 'json',
data: {id:event.id, start:event.start_time, end: event.end_time}
});
},
});
});
During drag-and-drop operations, I encounter the following error message:
ActiveRecord::RecordNotFound (Couldn't find Event with 'id'=update):
app/controllers/events_controller.rb:74:in `set_event'
Upon checking the console, all events appear to have IDs assigned to them. However, it's possible that during the drag-and-drop process, a newly created event may not have an ID associated with it.