Commit 6ecba9c7

mo khan <mo@mokhan.ca>
2014-11-21 21:05:53
add category lookup to api v2.
1 parent 5c5f82d
Changed files (5)
app/controllers/api/v2/categories_controller.rb
@@ -0,0 +1,9 @@
+module Api
+  module V2
+    class CategoriesController < ApplicationController
+      def show
+        @category = Category.find(params[:id])
+      end
+    end
+  end
+end
app/views/api/v2/cakes/_cake.json.jbuilder
@@ -2,6 +2,7 @@ json.id cake.id
 json.name cake.name
 json.description cake.story
 json.author cake.user.id
+json.category cake.category.id
 json.photos cake.photos.pluck(:id)
 json.createdAt cake.created_at
 json.updatedAt cake.updated_at
app/views/api/v2/categories/_category.json.jbuilder
@@ -0,0 +1,5 @@
+json.id category.id
+json.name category.name
+json.slug category.slug
+json.createdAt category.created_at
+json.updatedAt category.updated_at
app/views/api/v2/categories/show.json.jbuilder
@@ -0,0 +1,3 @@
+json.category do
+  json.partial! @category, category: @category
+end
config/routes.rb
@@ -71,6 +71,7 @@ Cake::Application.routes.draw do
       resources :cakes, only: [:index, :show]
       resources :photos, only: [:index, :show]
       resources :users, only: [:show]
+      resources :categories, only: [:show]
     end
   end