emberjs/ember.js — pull request #2252 by drogus (2013-03-10 02:15:57+00:00)
Title: [WIP] Refresh href in linkTo when one of the params or properties change

I've already opened a similar pull request here #2181, but as I mentioned in the description, it didn't handle the case when an attribute changes. This pull request is not technically ready, I would need to add more tests and I would need to make changes in `vendor/router.js` in the actual router repo, but I submit it for discussion (specifically, if this has chances to be merged in).

The problem, which this PR tries to resolve is described here: #2241. To fix it, we need to refresh the href attribute whenever one of the properties used to generate it changes.

The idea behind this is that in most cases, when dynamic segments are used, serialize method needs an `id` to generate an URL. In the rare cases, when it needs something else, we could require a bit more declarative approach:

```javascript
App.PostRoute = Ember.Route.extend({
serializePaths: ['slug'], // I suck at naming, halp!
serialize: function(post) {
return { slug: post.get('slug'); }
}
});
```

One more addition, which I would do on top of things already available in this PR is to set `#` as an URL if any of the params or properties is null. This would allow to just forget about problems in #2241.

Imagine the case where you display a list of posts (including links) and you insert a newly created post onto the list. Now you need to generate an URL for the new post, but id is obviously not available yet. You can do what I suggested in #2241 and just cover the link with `{{#if post.id}}`, but now you don't have the link at all. The ideal thing to do would be to render the link with `#` as a href and then update it as soon as record is saved and has an id.