Question

How would you get post/my-title (with a custom slug) instead of posts/2 (with id) in Ember.js?

My approach was to add and use a slug in my model but it doesn't work on direct access. Using a {{link-to}} helper it works, also the slug. I assume the error lies in the PageRoute's model. Tried return this.store.find('page', {'slug': params.page_slug}) without any luck.

Example code: http://emberjs.jsbin.com/AVAgUZAb/5/edit

Était-ce utile?

La solution

You're mismatching versions of Ember Data. In the PageRoute you are using the model definition to try and find the record which is no longer correct. See https://github.com/emberjs/data/blob/master/TRANSITION.md

Additionally you really should just replace id with the slug since you've essentially rendered the idea of unique items worthless (aka slug doesn't have to be unique, but id does, so what happens when you have multiple items with the same slug?) If your slugs will always be unique, you might as well use them as the id there is no constraint that id must be numeric.

http://emberjs.jsbin.com/AVAgUZAb/9/edit

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top