0

I'm attempting to add some actions to the nested route of Publishables in Ember:

Router.map(function() {
  this.resource('publishables', {path: '/publishables'}, function() {
    this.resource('publishable', { path: ':publishable_id' });
  });
});

export default Router;

The Publishables route:

export default Ember.Route.extend({
  model: function(params) {
    return this.store.find('publishable', { page: params.page });
  }
});

The Publishables model:

export default DS.Model.extend({
  title: DS.attr(),
  description: DS.attr(),

  authors: DS.hasMany('author', { async: true }),
  category: DS.belongsTo('category', { async: true }),

  published: DS.attr(),
  publish_from: DS.attr(),
  slug: DS.attr(),

  contentType: DS.attr()
});

The Publishables controller:

export default Ember.ArrayController.extend({

  actions : {
    preview: function(id) {
      this.transitionToRoute('publishable', id);
    }
  }

});

And the Publishables template:

<h2>Publishables</h2>
{{#each}}
  <p {{action "preview" id}}>{{title}}</p>
{{/each}}

{{outlet}}

This works wonderfully. If I click the {{title}}, it transitions to publishable/:id and the appropriate data is loaded in the {{outlet}}.

Now I would like to add some actions to Publishable. If I create a Publishable controller much like the Publishables controller, everything breaks. I believe this is due to Publishable being a child of Publishables. Can anyone steer me in to the right direction on how to get actions bound in the nested route?

tr3online
  • 1,429
  • 2
  • 24
  • 45
  • will you show the code you're using that isn't working? – Kingpin2k Jul 09 '14 at 03:27
  • It's mainly when i create a `PublishableController` I lose the context of the data being supplied by the model. In the publishable.hbs I lose access to `{{id}}`, `{{title}}`, etc. I'm not sure why this happens? As such I'm unable to create `actions: {}` inside said controller. Technically it should be inheriting from `Publishables` because it's a nested resource, correct? – tr3online Jul 09 '14 at 05:43

0 Answers0