diff --git a/Gemfile b/Gemfile index e21baa2c..96cc1673 100644 --- a/Gemfile +++ b/Gemfile @@ -50,4 +50,5 @@ gem 'acts_as_commentable_with_threading' gem 'prawn' gem 'prawn_rails' gem 'gravtastic' +gem 'active_model_serializers' diff --git a/Gemfile.lock b/Gemfile.lock index 0387fdfe..b9041a60 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,6 +15,8 @@ GEM rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) + active_model_serializers (0.8.1) + activemodel (>= 3.0) activemodel (3.2.11) activesupport (= 3.2.11) builder (~> 3.0.0) @@ -213,6 +215,7 @@ PLATFORMS ruby DEPENDENCIES + active_model_serializers acts_as_commentable_with_threading bcrypt-ruby (~> 3.0.0) bootstrap-sass diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb new file mode 100644 index 00000000..6ec4ef9d --- /dev/null +++ b/app/controllers/api/base_controller.rb @@ -0,0 +1,3 @@ +class Api::BaseController < ActionController::Base + protect_from_forgery +end diff --git a/app/controllers/api/v1/conferences_controller.rb b/app/controllers/api/v1/conferences_controller.rb new file mode 100644 index 00000000..d12cd99c --- /dev/null +++ b/app/controllers/api/v1/conferences_controller.rb @@ -0,0 +1,7 @@ +class Api::V1::ConferencesController < Api::BaseController + respond_to :json + + def index + respond_with Conference.all + end +end diff --git a/app/serializers/conference_serializer.rb b/app/serializers/conference_serializer.rb new file mode 100644 index 00000000..37d9cd1e --- /dev/null +++ b/app/serializers/conference_serializer.rb @@ -0,0 +1,23 @@ +class ConferenceSerializer < ActiveModel::Serializer + attributes :guid, :name, :description, :year, :socialtag, :date_range#, :url, :revision + + def name + object.short_title + end + + def description + object.title + end + + def year + object.start_date.try(:year) + end + + def socialtag + object.social_tag + end + + def date_range + object.date_range_string + end +end diff --git a/config/routes.rb b/config/routes.rb index 251a9ce9..73c1f786 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,6 +53,13 @@ Osem::Application.routes.draw do delete "/register" => "ConferenceRegistration#unregister" end end + + namespace :api, defaults: {format: 'json'} do + namespace :v1 do + resources :conferences, :only => :index + end + end + match "/admin" => redirect("/admin/conference") root :to => "home#index"