我有一个运行Ruby ruby“ 2.3.3”的小应用程序,并且训练了Rails 5.1.4来在其中的一部分中消耗FullCalendar。但是当我去那里时,什么也没显示。我已经尝试了所有方法并查看了论坛,但没有人遇到我的问题。有人可以帮我吗?
我已经安装了宝石
gem 'fullcalendar-rails'
gem 'momentjs-rails'
这是我的full_calendar.js
var initialize_calendar;
initialize_calendar = function() {
$('.calendar').each(function(){
var calendar = $(this);
calendar.fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
selectable: true,
selectHelper: true,
editable: true,
eventLimit: true,
events: '/events.json',
select: function(start, end) {
$.getScript('/events/new', function() {
$('#event_date_range').val(moment(start).format("MM/DD/YYYY HH:mm") + ' - ' + moment(end).format("MM/DD/YYYY HH:mm"))
date_range_picker();
$('.start_hidden').val(moment(start).format('YYYY-MM-DD HH:mm'));
$('.end_hidden').val(moment(end).format('YYYY-MM-DD HH:mm'));
});
calendar.fullCalendar('unselect');
},
eventDrop: function(event, delta, revertFunc) {
event_data = {
event: {
id: event.id,
start: event.start.format(),
end: event.end.format()
}
};
$.ajax({
url: event.update_url,
data: event_data,
type: 'PATCH'
});
},
eventClick: function(event, jsEvent, view) {
$.getScript(event.edit_url, function() {
$('#event_date_range').val(moment(event.start).format("MM/DD/YYYY HH:mm") + ' - ' + moment(event.end).format("MM/DD/YYYY HH:mm"))
date_range_picker();
$('.start_hidden').val(moment(event.start).format('YYYY-MM-DD HH:mm'));
$('.end_hidden').val(moment(event.end).format('YYYY-MM-DD HH:mm'));
});
}
});
})
};
$(document).on('turbolinks:load', initialize_calendar);
这是events_controller.rb
class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :destroy]
def index
@events = Event.where(start: params[:start]..params[:end])
end
def show
end
def new
@event = Event.new
end
def edit
end
def create
@event = Event.new(event_params)
@event.save
end
def update
@event.update(event_params)
end
def destroy
@event.destroy
end
private
def set_event
@event = Event.find(params[:id])
end
def event_params
params.require(:event).permit(:title, :date_range, :start, :end, :color)
end
end
我的模型event.rb
class Event < ApplicationRecord
validates :title, presence: true
attr_accessor :date_range
def all_day_event?
self.start == self.start.midnight && self.end == self.end.midnight ? true : false
end
end
我的视图calendar / index.html.erb
<div class='calendar'></div>
我的calendar_controller.rb
class CalendarController < ApplicationController
def index
end
end
我的溃败
get '/calendar/index', to: 'calendar#index', as: :calendar_index