Search code examples
ember.jsember-dataember-router

ember.js: dynamic segments and queries


I have a problem with resources in ember.js.

given these router:

App.Router.map ->
  @route "index", path: "/"
  @resource "transport_documents", ->
    @resource "transport_document", path: ":transport_document_id"

and this routes:

App.TransportDocumentsRoute = Ember.Route.extend
  model: -> App.TransportDocument.find()

App.TransportDocumentRoute = Ember.Route.extend
  model: (params)-> 
    App.TransportDocument.find(params.id)
  • when i navigate to /transport_documents my server side call is: /api/transport_documents, as expected
  • when i navigate to /transport_documents/1 i expect this call is done: /api/transport_documents/1, but it's not. no calls to my server

Is it an expected situation? if no, what should i do to force my app doing this query? I want more details in the show view, and less in the index.

thanks


Solution

  • params will contain the dynamic segment name you specified. In your case you need to use:

    model: (params)-> 
      App.TransportDocument.find(params.transport_document_id)
    

    See this example in the Ember routing guide for more information.