Commit 846e51ab

mo khan <mo@mokhan.ca>
2014-11-19 04:53:46
add api/v2/cakes/1.json
1 parent 19fecb1
Changed files (5)
app/controllers/api/v2/cakes_controller.rb
@@ -4,6 +4,10 @@ module Api
       def index
         @cakes = Creation.all
       end
+
+      def show(id = params[:id])
+        @cake = Creation.find(id)
+      end
     end
   end
 end
app/views/api/v2/cakes/_cake.json.jbuilder
@@ -0,0 +1,5 @@
+json.id cake.id
+json.name cake.name
+json.description cake.story
+json.createdAt cake.created_at
+json.updatedAt cake.updated_at
app/views/api/v2/cakes/index.json.jbuilder
@@ -1,7 +1,3 @@
 json.cakes @cakes do |cake|
-  json.id cake.id
-  json.name cake.name
-  json.description cake.story
-  json.created_at cake.created_at
-  json.updated_at cake.updated_at
+  json.partial! 'cake', cake: cake
 end
app/views/api/v2/cakes/show.json.jbuilder
@@ -0,0 +1,3 @@
+json.cake do
+  json.partial! 'cake', cake: @cake
+end
config/routes.rb
@@ -68,7 +68,7 @@ Cake::Application.routes.draw do
       resources :logins, only: [:create]
     end
     namespace :v2 do
-      resources :cakes, only: [:index]
+      resources :cakes, only: [:index, :show]
     end
   end