Refresh current route's model from application template


I want a reload button to appear at the top of every page in my app, so I think it makes sense to have the UI for it in the application.hbs template. The purpose of the button is to refresh the current route’s model.

But in order to refresh the model for the current route, the button needs to be able to communicate with the current route (to call this.refresh();).

What is a good way to accomplish this?


You might be able to use the application controller’s currentRouteName property to lookup the current route off the container and invoke refresh on it.

That might look something like:

// app/controllers/application
actions: {
  refreshCurrentModel() {
    let route = Ember.getOwner(this).lookup(`route:${get(this, 'currentRouteName')}`);
    return route.refresh();
{{!-- application.hbs --}}
<button {{action 'refreshCurrentModel'}}>Refresh</button>

This is one way I could think of using the public APIs.


Thanks @jasonmit – I’ll give that a go.