Refreshing model on multiple requests same url


#1

I want to use a remote service that exposes an api for returning a random item, something like this:

http://remote-service.com/api/v1/items/random

However, from within Ember I cannot get the model to refresh and make an additional request to pick up the newer results.

I’ve tried various things, including:

model.refresh();
transitionToRoute('items.random');

but this doesn’t seem to work either.

Is there an easier more elegant manner to achieve this that I am overlooking?


#2

Does reload not do the job?

http://emberjs.com/api/data/classes/DS.Model.html#method_reload


#3

Sure, if I hit F5 (refresh browser) it works fine.

Only using the button with action doesn’t :frowning:


#4

I mean the reload method :wink:


#5

Yes, as I said in the original message (I meant model.reload() sorry). Here’s a code sample:

actions: {
  ...
  random: function() {
    var model = this.get('model');
    if (model) {
      var _this = this;
      model.reload().then(function(model){
         _this.transitionToRoute('entries.random');
      });
    }
  },
  ...
}

#6

:wink: Not sure but this.controller.get('model').reload() seems better. You need to reload the data on the controller.


#7

That’s not going to work because the action is being handled from within the controller already and NOT within the route, any other ideas?


#8

Not much ideas. Do you use setupController on the route? I remember reading this and perhaps your model is also not fetched.


#9

To me requesting a random item seems to fit better with store.query as opposed to refreshing a model.