0

In my current Ember setup, I retrieve a store for the Index Route. This works fine.

 App.IndexRoute = Ember.Route.extend({

    model: function(){      
          var store = this.store.find('index');        
          return store;
        }

  });

However, I wish to create a custom form object for the same route, and therefore following the advice of this SO answertried to return two models for the Index Route like this, however, I now get the error

Error while processing route: index that is not defined ReferenceError: that is not defined

New Code

  App.IndexRoute = Ember.Route.extend({

    model: function(){      

          return Ember.RSVP.hash({
           store: this.store.find('index'),
           customform: App.CustomForm.create()
          });
       }


  });

How can I add a second model to this route?

Update The index model had a date property that I was using to sort the items in the index model

App.IndexController = Ember.ArrayController.extend({
        sortProperties: ['date'],
        sortAscending: false,

I was originally displaying the index model with this in the html

    {{#each item in arrangedContent}}
 <li> {{some-component id=item.customid date=item.date data=item.junk}} </li>

    {{/each}}

By adding the second model, whether or not i use the store to create a record, I get this error and the data from the store doesn't load in the html

 Error while processing route: index undefined is not a function TypeError: undefined is not a function

Also, I don't actually need to persist the second model I'm trying to add, so I don't desire to make it a store. In the SO answer I linked to, second models were added that weren't persisted.

Community
  • 1
  • 1
BrainLikeADullPencil
  • 11,313
  • 24
  • 78
  • 134
  • why you need empty model object, if you explain your original problem may be there is a good solution already in ember js – Sushant Feb 09 '15 at 18:56
  • @sushant I'm trying to create a form object that I can use in the index route following these instructions http://stackoverflow.com/questions/18309544/how-do-i-handle-form-submission-in-ember-js/18323040#18323040 – BrainLikeADullPencil Feb 09 '15 at 19:01

2 Answers2

1

It looks like you should be using the store to create your new custom form record:

App.IndexRoute = Ember.Route.extend({
    model: function(){      
        return Ember.RSVP.hash({
            store: this.store.find('index'),
            customform: this.store.createRecord('customForm')
        });
    }
});
Oren Hizkiya
  • 4,420
  • 2
  • 23
  • 33
  • Thank you. I'm not intending to persist the data, merely using the object to create a custom form as described here http://stackoverflow.com/questions/18309544/how-do-i-handle-form-submission-in-ember-js/18323040#18323040 – BrainLikeADullPencil Feb 09 '15 at 19:12
  • It also doesn't get rid of the error message. I think the problem might be that I display data in the index.html {{#each item in arrangedContent}} that's expecting the old setup. Furthmore, the second model is just an ember object that I extend to create the custom form `Ember.Object.extend({` – BrainLikeADullPencil Feb 09 '15 at 19:17
  • In that case it may make sense to setup custom form on your controller: `setupController : function(controller, model){ controller.set("customform", App.CustomForm.create()); }` - are there any parameters you are trying to pass based on the route? – Oren Hizkiya Feb 09 '15 at 19:25
  • If you post the rest of your code it may help determining where the issue lays. – Oren Hizkiya Feb 09 '15 at 19:26
  • I added more information. Thanks for your assistance. – BrainLikeADullPencil Feb 09 '15 at 19:41
1

You're going to want to create your customForm through your store:

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return Ember.RSVP.hash({
      store: this.store.find('index'),
      customForm: this.store.createRecord('customForm')
    });
  }
});
Collin Graves
  • 2,207
  • 15
  • 11