ember.js dynamic route issue -
i have app.user , app.contact models identical , inherit a base class:
app.person = ds.model.extend({ firstname: ds.attr('string'), surname: ds.attr('string'), email: ds.attr('string'), fullname: function(){ return this.get('firstname') + " " + this.get('surname'); }.property('firstname', 'surname'), }); app.contact = app.person.extend({ }); app.user = app.person.extend({ });
i want somehow pass these objects new route allow me email them automatically. have mail object references person polymorphic relationship:
app.mail = ds.model.extend({ recipients: ds.hasmany('app.person', {polymorphic: true}), });
the problem have shown in fiddle here.
for reason model not getting set in app.mailpersonroute route , mystified why.
because router has nested routes:
app.router.map(function() { this.resource('mail', function(){ this.route('person', {path: 'person/:person_id'}); }); });
you creating {{linkto}}
passing nested route name mail.person
:
<script type="text/x-handlebars" data-template-name="index"> {{#each model}} <p>mail {{#linkto mail.person this}}{{fullname}}{{/linkto}} {{/each}} </script>
that must reflected template names (as per conventions), particularly template related route. have:
<script type="text/x-handlebars" data-template-name="mail"> in mail {{email}} </script>
it should be:
<script type="text/x-handlebars" data-template-name="mail/person"> in mail {{email}} </script>
nested routes carry name of parent resources in key name, while resources don't have parent resource in names, if declared under resource.
note: not required, maybe want change serialize
similar or more elegant implementation of following:
serialize: function(model){ var _persontype = 'contact'; if(model instanceof app.user) { _persontype = 'user' } return { person_type: _persontype, person_id: model.get('id') }; }
this change require routes defined similar following:
app.router.map(function() { this.resource('mail', function(){ this.route('person', {path: ':person_type/:person_id'}); }); });
implementing prevent href
of links equal if have both user , contact same id. in current state, if visit 1 of these links browser think both links visited. again, not requirement or anything.
Comments
Post a Comment