0

I am trying to add an WatchList feature in the existing code discourse ember rails application

I have addded the following code

 Discourse.Route.buildRoutes(function() {
    var router = this;

    this.resource('watchLists', { path: '/watch_lists' }, function() {
        this.resource('watchList', {path: ':watch_list_id'});
     });
  });

In the ember Controller

 Discourse.WatchListsController = Discourse.ObjectController.extend({});

In the ember model

   Discourse.WatchList = Discourse.Model.extend({});

   Discourse.WatchList.reopenClass({
      find: function() {
          jQuery.getJSON("watch_lists").then(function(json) {
          var watch_lists = json.watch_lists.map(function(attrs) {
          return Discourse.WatchList.create(attrs);
      });
   });

In the ember view js

   Discourse.WatchListsView = Ember.View.extend({});

In ember route js

     Discourse.WatchListsRoute = Discourse.Route.extend({
         model: function() {
            return Discourse.WatchList.find();   
         }
    });

When i renderring the handlebars template I am getting an WatchListsController object withot the data we have got from the ajax.

Can any body point out where i am doing wrong.

user1683039
  • 75
  • 1
  • 8

1 Answers1

2

I see two possible problems.

First, you probably want WatchListsController to extend Discourse.ArrayController, not Discourse.ObjectController.

Second your reopen block is not valid JavaScript in the example code that you posted. I count four { but only two }. You probably want something kind of like this:

Discourse.WatchList.reopenClass({
  find: function() {
    return jQuery.getJSON("watch_lists").then(function(json) {
      return json.watch_lists.map(function(attrs) {
        return Discourse.WatchList.create(attrs);
      }
    });
  }
});
Jeremy Green
  • 8,547
  • 1
  • 29
  • 33