Daniel
Daniel

Reputation: 861

how to deal with the unknown id with ember-data and emberjs

Based on Rails, Emberjs and ember-data

Route

App.Router.map ->
  @resource "sentences", ->
    @resource "sentence",
      path: ":sentence_id", ->

Model

App.Sentence = DS.Model.extend(
  subject: DS.attr("string")
)

visit the url

http://localhost:3000/#/sentences/5

if the sentence with the id 5 does not exist in the server, how to deal with that?

Upvotes: 1

Views: 110

Answers (2)

Daniel
Daniel

Reputation: 861

how to use the two params 'reason', 'transition'
Is it possible to show one example

why does it have two params here?

Upvotes: 0

Darshan Sawardekar
Darshan Sawardekar

Reputation: 5075

If your server sends a 404, for such a request, Ember will raise an exception which can be handled via an errors handler on the route. From there you can display this in the UI or transitionTo another route that can display the error.

App.PostRoute = Ember.Route.extend({
  events: {
    error: function(reason, transition) {
      // display error or transitionTo here
    }
  }
});

Upvotes: 1

Related Questions