I have an object route in the router (using ember-data with standard REST backend) with connectOutlets
that simply deserializes and loads the object and plugs it into the outlet.
# inside router
action: Ember.Route.extend
route: 'object/:object_id'
connectOutlets: (router, object) ->
unless object.get('isLoaded') # What goes here to tell if the object wasn't found?
#
# handle this case (e.g., redirect)
#
else # otherwise proceed as normal
router.get('applicationController').connectOutlet('object', object)
When I navigate to localhost/#object/object_that_doesnt_exist
, the router deserializes the url, attempts to load the object (server logs show a HTTP GET request for localhost/objects/object_that_doesnt_exist), gets a 404, and instead creates a new object with id set to object_that_doesnt_exist
.
I want to detect this and handle the case. Right now, I am checking the isLoaded
property, which does differentiate between existing models and nonexisting models, but I'm not sure this is the best way.
Ideally, there would be a method similar to Rails' new_record?
.