Commit c7ee6fd5

mo <mo.khan@gmail.com>
2017-09-25 00:06:07
load tutorials collection on the page.
1 parent 576a045
Changed files (7)
app
app/assets/javascripts/controllers/my/tutorials_controller.js.coffee
@@ -2,7 +2,7 @@ class csx.Controllers.My.TutorialsController extends Marionette.Controller
   views: csx.Views.My.Tutorials
   initialize: (options) ->
     @content_region = csx.Application.content_region
-    @tutorials = csx.Application.request('TutorialsRepository')
+    @tutorials = csx.Collections.Tutorial
 
   index: ->
     @selectTab()
app/assets/javascripts/views/my/cakes/new_view.js.coffee
@@ -57,5 +57,5 @@ class csx.Views.My.Cakes.NewView extends Marionette.ItemView
   serializeData: ->
     {
       cake: @model.toJSON(),
-      categories: csx.Collection.Category.toJSON(),
+      categories: csx.Collections.Category.toJSON(),
     }
app/assets/javascripts/cakeside.js.coffee
@@ -14,6 +14,7 @@ window.csx =
   Routers: {}
   Views: {}
   Controllers: { My: {} }
+
   initialize: (data) ->
     $(document).ajaxSend  (event, xhr) ->
       if data.access_token
@@ -38,7 +39,6 @@ window.csx =
         Backbone.history.start()
 
     @cakes = new csx.Collections.CakesCollection()
-    @tutorials = new csx.Collections.TutorialsCollection()
 
     csx.Application.reqres.setHandler 'CakesRepository', =>
       @cakes
@@ -51,11 +51,8 @@ window.csx =
         @photos_cache[cake_id] = photos
         photos.fetch(reset: true)
         photos
-    csx.Application.reqres.setHandler 'TutorialsRepository', =>
-      @tutorials
     csx.Application.reqres.setHandler 'ProfilesRepository', =>
       @profiles ||= new csx.Collections.ProfilesCollection()
 
-    @tutorials.fetch(reset: true)
     @cakes.fetch(reset: true).done ->
       csx.Application.start()
app/controllers/api/v1/cakes_controller.rb
@@ -2,7 +2,7 @@ module Api
   module V1
     class CakesController < ApiController
       def index
-        @cakes = current_user.creations
+        @cakes = current_user.creations.includes(:category, :photos, :tags, :tag_taggings)
       end
 
       def show
app/controllers/my/kitchens_controller.rb
@@ -3,6 +3,7 @@ module My
     def show
       @tags = Tag.unique_tags
       @cakes = current_user.creations.includes(:category, :photos, :tags, :tag_taggings)
+      @tutorials = current_user.tutorials.includes(:tags, :tag_taggings)
     end
   end
 end
app/views/application/json/_tutorials.jbuilder
@@ -0,0 +1,16 @@
+json.cache! items do
+  json.array! items do |tutorial|
+    json.id tutorial.id
+    json.heading tutorial.heading
+    json.description tutorial.description
+    json.url tutorial.url
+    json.image_url tutorial.image_url
+    json.author tutorial.author
+    json.author_url tutorial.author_url
+    json.created_at tutorial.created_at
+    json.updated_at tutorial.updated_at
+    json.tags tutorial.tags do |tag|
+      json.name tag.name
+    end
+  end
+end
app/views/my/kitchens/show.html.erb
@@ -10,6 +10,8 @@
 
 <%= backbone_collection_for @categories %>
 <%= backbone_collection_for @tags %>
+<%= backbone_collection_for @cakes %>
+<%= backbone_collection_for @tutorials %>
 
 <%= javascript_tag do %>
   csx.initialize({ access_token: '<%= current_user.authentication_token %>' });