Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very confused with ember redirect and/or renderTemplate

Tags:

ember.js

I'm new to ember, and am really struggling with how to accomplish what should be a fairly simple task.

I'm trying to put my resume into an ember app. As part of my resume, I have a few references.

When someone hits the 'references' link in the navigation, I'd like it to show the links to each reference, as well as the first reference, displayed as a child to the links.

Apparently, my options here are to either redirect to the 'references/1' url(not really ideal), or display the 'reference' template.

I'd build a JSFiddle for this, but jsfiddle seems to be broken as I can't load or view anything already up there.

I have this working with regular routes, where I load references, it shows the links, and if I click on a link, or load the page directly with the 'references/2' url, it shows the correct content.

If I redirect using

App.ReferencesRoute = Ember.Route.extend({
    model: function(){
        return App.References.find();
    },
    redirect: function(){
        this.transitionTo('reference',App.References.find(1));
    }

});

I get the url redirecting correctly, but I don't get the links to the references. I do get the 'reference' template loaded, but the model isn't getting passed. I've tried using this.modelFor('references').get('firstObject') but that doesn't return anything either, which is why I'm using find(1).

If I try to do this with the render template and controller like this

App.ReferencesRoute = Ember.Route.extend({
    model: function(){
        return App.References.find();
    },
    renderTemplate: function(){
        this.render();
        this.render('reference',{into: 'references',controller:'reference'});

    }
});

App.ReferenceController = Ember.ObjectController.extend({
    letter: 'test letter' 
});

I get the links and the 'test letter' message but I run into a few other problems.

1) I can't figure out how to pass the Reference controller the first model so that it actually returns the same as if the user was at the '/references/1' url

2) If I click the links, the selected letter is not displayed, meaning the links don't work if I use the controller.

3) I'd want the first link to be active, as that is the letter which is already showing, but that is a minor detail compared to the other issues.

Am I going about this completely wrong? Is there something big that I'm missing?

like image 507
pedalpete Avatar asked Jan 18 '26 21:01

pedalpete


1 Answers

for passing the model via a redirect i use something like this:

App.ReferencesIndexRoute = Ember.Route.extend({
   model    : function(){
       return App.References.find();
   },
   redirect : function(){
      var model = this.controllerFor('references').get('model');
      this.transitionTo('reference', model);
   }
});
like image 88
theremin Avatar answered Jan 21 '26 00:01

theremin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!