In my route I have a method that tries to request a list of models from the server
model: ->
App.MyModel.find
projectId: (@modelFor "project").id
Now obviously sometimes this might return a 404.
At the moment when this happens, Ember just stops doing anything. No view is rendered, no controller is setup.
So how can I properly handle the 404 (ie show an error view)?
Index Routes. At every level of nesting (including the top level), Ember automatically provides a route for the / path named index . To see when a new level of nesting occurs, check the router, whenever you see a function , that's a new level. For example, if you write a simple router like this: app/router.js Router.
Ember and Ember Data are entirely client-side JavaScript, so it is possible for them to interface with any backend. In fact, that is one of the most compelling aspects of Ember Data. There are many useful examples on the Web of developers using anything from .
Bad news: right now, ember-data doesn't do anything when it gets a 404 on find(). At all. The model sits in the 'loading' state forever.
There are no non-completely-stupid options, here, in my opinion. What I would probably do as a last resort is add a notFound
attribute on my DS.Model, and instead of returning 404, return JSON with notFound
set to true
. It's painful, I know...
--- I had originally offered a solution of overriding find
in a subclass of RESTAdapter
. Then I noticed that find
DOES NOT get passed the record instance it is supposedly loading. So, no go on handling 404s by putting the record into an error state.
[NOTE: ember-data has changed dramatically since March 2013, the information in this answer may no longer be operative]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With