From 14468afef0b6ad16bb92a95ab6322cfbf6707ffc Mon Sep 17 00:00:00 2001 From: Aditya Kapoor Date: Wed, 25 Jun 2014 23:19:01 +0530 Subject: [PATCH 1/2] Fix Query for the fetching of the events on calendar --- .../fullcalendar_engine/events_controller.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/fullcalendar_engine/events_controller.rb b/app/controllers/fullcalendar_engine/events_controller.rb index c32e043..897adc7 100644 --- a/app/controllers/fullcalendar_engine/events_controller.rb +++ b/app/controllers/fullcalendar_engine/events_controller.rb @@ -23,10 +23,15 @@ def new end def get_events - @events = Event.where('starttime >= :start_time and - endtime <= :end_time', - start_time: Time.at(params['start'].to_i).to_formatted_s(:db), - end_time: Time.at(params['end'].to_i).to_formatted_s(:db)) + start_time = Time.at(params[:start].to_i).to_formatted_s(:db) + end_time = Time.at(params[:end].to_i).to_formatted_s(:db) + + @events = Event.where(' + (starttime >= :start_time and endtime <= :end_time) or + (starttime >= :start_time and endtime > :end_time and starttime <= :end_time) or + (starttime <= :start_time and endtime >= :start_time and endtime <= :end_time) or + (starttime <= :start_time and endtime > :end_time)', + start_time: start_time, end_time: end_time) events = [] @events.each do |event| events << { id: event.id, From 8c7c14dcf53fd0fa90123a09c23e274649a14f7f Mon Sep 17 00:00:00 2001 From: Aditya Kapoor Date: Wed, 25 Jun 2014 23:20:49 +0530 Subject: [PATCH 2/2] Rename get_events to index action in the events_controller --- app/controllers/fullcalendar_engine/events_controller.rb | 2 +- config/initializers/configuration.rb | 2 +- config/routes.rb | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/fullcalendar_engine/events_controller.rb b/app/controllers/fullcalendar_engine/events_controller.rb index 897adc7..80dd322 100644 --- a/app/controllers/fullcalendar_engine/events_controller.rb +++ b/app/controllers/fullcalendar_engine/events_controller.rb @@ -22,7 +22,7 @@ def new end end - def get_events + def index start_time = Time.at(params[:start].to_i).to_formatted_s(:db) end_time = Time.at(params[:end].to_i).to_formatted_s(:db) diff --git a/config/initializers/configuration.rb b/config/initializers/configuration.rb index 70db4d8..990c4fe 100644 --- a/config/initializers/configuration.rb +++ b/config/initializers/configuration.rb @@ -15,4 +15,4 @@ 'timeFormat' => "h:mm t{ - h:mm t}" } FullcalendarEngine::Configuration.merge!(config) -FullcalendarEngine::Configuration['events'] = "#{FullcalendarEngine::Configuration['mount_path']}/events/get_events" +FullcalendarEngine::Configuration['events'] = "#{FullcalendarEngine::Configuration['mount_path']}/events" diff --git a/config/routes.rb b/config/routes.rb index 72b3099..56314f8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,9 @@ FullcalendarEngine::Engine.routes.draw do - root :to => 'events#index' resources :events do - collection do - get :get_events - end member do post :move post :resize end end + root :to => 'events#index' end \ No newline at end of file