Commit 55f4bb9

mo khan <mo@mokhan.ca>
2014-04-12 03:28:26
add route to load a single video and all videos.
1 parent 2a85dcd
Changed files (7)
app/assets/javascripts/controllers/videos_controller.js
@@ -1,2 +1,2 @@
-Mocode.VideosController = Ember.Controller.extend({
+Mocode.VideosController = Ember.ArrayController.extend({
 });
app/assets/javascripts/routes/video_route.js
@@ -0,0 +1,8 @@
+Mocode.VideoRoute = Ember.Route.extend({
+  model: function(params) {
+    return this.store.find('video', params.video_id);
+  },
+  serialize: function(post) {
+    return { post_id: post.get('id') };
+  }
+});
app/assets/javascripts/templates/video.hbs
@@ -0,0 +1,1 @@
+{{title}}
app/assets/javascripts/templates/videos.hbs
@@ -1,4 +1,3 @@
-hello dj
 <ul>
   {{#each controller}}
   <li>{{title}}</li>
app/assets/javascripts/router.js.coffee
@@ -1,5 +1,5 @@
 # For more information see: http://emberjs.com/guides/routing/
 
 Mocode.Router.map ()->
-   @resource('videos')
-
+  @resource 'videos'
+  @resource 'video', { path: '/video/:video_id' }
app/controllers/videos_controller.rb
@@ -0,0 +1,20 @@
+class VideosController < ApplicationController
+  def index
+    render json: [
+      {
+        id: 1,
+        title: 'getting jiggy with it',
+        description: 'supa fly funky dancing'
+      },
+      {
+        id: 2,
+        title: 'getting jiggy with it',
+        description: 'supa fly funky dancing'
+      },
+    ]
+  end
+
+  def show
+    render json: { id: 1, title: 'getting jiggy with it', description: 'supa fly funky dancing' }
+  end
+end
config/routes.rb
@@ -1,5 +1,6 @@
 Mocode::Application.routes.draw do
   resources :logins, only: [:new, :create]
+  resources :videos, only: [:index, :show]
   get 'dashboard', to: 'dashboard#index'
   root 'dashboard#index'
   # The priority is based upon order of creation: first created -> highest priority.