From 5ecafd9573952f7696942e464855c5e5b9cd9b6b Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Mon, 5 Oct 2015 15:24:37 +0300 Subject: [PATCH] Introduce a rudimentary JSON export of events --- app/controllers/api/application_controller.rb | 2 ++ app/controllers/api/events_controller.rb | 14 ++++++++++++++ config/routes.rb | 6 ++++++ 3 files changed, 22 insertions(+) create mode 100644 app/controllers/api/application_controller.rb create mode 100644 app/controllers/api/events_controller.rb diff --git a/app/controllers/api/application_controller.rb b/app/controllers/api/application_controller.rb new file mode 100644 index 0000000..b9568e7 --- /dev/null +++ b/app/controllers/api/application_controller.rb @@ -0,0 +1,2 @@ +class Api::ApplicationController < ::ApplicationController +end diff --git a/app/controllers/api/events_controller.rb b/app/controllers/api/events_controller.rb new file mode 100644 index 0000000..4ae04b2 --- /dev/null +++ b/app/controllers/api/events_controller.rb @@ -0,0 +1,14 @@ +class Api::EventsController < Api::ApplicationController + def index + @conference = find_conference + @events = @conference.events.includes(:track) + + render json: @events, include: :track + end + + private + + def find_conference + Conference.find params[:conference_id] + end +end diff --git a/config/routes.rb b/config/routes.rb index 02ca330..97b66fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,12 @@ Rails.application.routes.draw do end end + namespace :api do + resources :conferences, only: [] do + resources :events, only: :index + end + end + namespace :management do root to: 'home#index'