Custom URIs using ids


Hello, I have full control over a rails api and an emberjs front end.

Currently lets say we have a resource named foo that can be found only by id in the api and has a name attribute. Is it possible to implement an ember route


so that the request in store is done using the id param I pass to the route but the uri in the browser takes the name of another attribute. In short the following scenario:

Starting template {{link-to "" foo}} route makes a request at the api (or the ember store):


the URI in the browser is constructed like

/foos/ or /foos/

If this is not possible, then is the only way to find the foo method by name:



Finally if we look at facebook’s front end and api, in the front end we have a URI for a user of the form:


however it is not possible to query the api by a user’s name. Does this mean that they dont allow external developers to query their api by a user’s name but they do query it by name in their app ?



On the landing route you can customize how the URL is populated using the serialize() method: That method returns an object that has a matching property to the dynamic segment and ember will populate it in the URL.

That should allow you to pass the full model and get a different URL than what you might use to do the lookup in the store.

However, if they access the route directly with the URL, your model method on the route will need to take that “name” and do a proper query to get the model to resolve. So if your page with the link-to normally resolves foo for you, you’ll need to teach your “” route how to do that as well since a user coming in with the direct URL will not be passing an already populated foo, they’ll hit your model route passing in only the name. To do this in the model you’d need to use store.query not store.find in the newest ember-data:

In older ember data it would still be store.find(…{name:}), passing not wrapped in an object will try to use as the id.