diff --git a/app/controllers/fullcalendar_engine/events_controller.rb b/app/controllers/fullcalendar_engine/events_controller.rb index c32e043..80dd322 100644 --- a/app/controllers/fullcalendar_engine/events_controller.rb +++ b/app/controllers/fullcalendar_engine/events_controller.rb @@ -22,11 +22,16 @@ def new end 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)) + 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) + + @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, 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