Here is the current model structure:
class User < ActiveRecord::Base
has_and_belongs_to_many :event_series
has_many :events, through: :event_series
end
class Event < ActiveRecord::Base
belongs_to :event_series
end
class EventSeries < ActiveRecord::Base
has_and_belongs_to_many :users
has_many :events
end
class UserEventSeries < ActiveRecord::Base
belongs_to :event
belongs_to :user
end
A user is assigned to an event series, which contains multiple events. When a user logs in and accesses their dashboard, I want to utilize Fullcalendar to display all events that the user is currently associated with.
I have successfully retrieved all of the user's events using jbuilder and generated JSON data. However, these events are not displaying on the calendar located at http://localhost:3000/users/1.
View the JSON data at http://localhost:3000/users/1.json:
{
"events": [{
"all_day": false,
"created_at": "2017-04-06T14:16:24-05:00",
"description": "sdsdsdsdsdd",
"endtime": "2017-04-06T15:16:00-05:00",
...
}, {...and so on
Jbuilder file: show.json.jbuilder
json.events @user.events
Fullcalendar Script:
$(document).ready(function(){
$('#calendar').fullCalendar({
editable: false,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultView: 'agendaWeek',
height: 500,
slotMinutes: 15,
events: "/users/1.json",
timeFormat: 'h:mm t{ - h:mm t} ',
dragOpacity: "0.5",
eventClick: function(event, jsEvent, view) {
$('#modalTitle').html(event.title);
$('#modalBody').html(event.description);
$('#eventUrl').attr('href',event.url);
$('#fullCalModal').modal();
},
});
});