Why my renderTemplate doesn't work at all?


#1

Recently I read the article “An In-depth Introduction to Emberjs” and followed step by step of its example code, but when it goes to renderTemplate part, it doesn’t work at all. Here is my code(not all the code):

app.js:

App = Ember.Application.create();

App.Router.map(function() {
  this.resource('users', function() {
    this.resource('user', {path : '/:user_id'}, function() {
      this.route('edit');
    });
    this.route('create');
  });
  this.resource('tests');
});

App.UsersCreateRoute = Ember.Route.extend({
  model : function() {
    return Ember.Object.create({});
  },
  renderTemplate : function() {
    this.render('user.edit', {
      controller : 'usersCreate'
    });
  }
});

It’s weird that when I go to /index.html#/users/create, user/edit template doesn’t come into sight, but there is no error reported in the console, and when I defined a template whose id is users/create, this users/create template got rendered on the page.

So why here the renderTemplate method doesn’t work?

Thanks.


#2

@hwoarangzk Can you give sample jsbin, then can find issue easily.

IMO If you use ember app kit structure will be easier for you

http://iamstef.net/ember-app-kit/guides/getting-started.html

Ember Cli (http://iamstef.net/ember-cli/) is a command line utility and will be create project template (structure) with ember app kit…


#3

if your template name is user/edit you’ll probably want to use that as the template name for this.render('user/edit', ...)


#4

Hi @jhsu, I also tried ‘user/edit’ as the parameter for the render, but it doesn’t work as well.

And @YIk, due to the company policy, I can’t get access to JSBin, but I’ll the the link you gave to me

Thank you all :slight_smile:


#5

It totally should have worked: JSBin Demo.

If it doesn’t, make sure your user/edit template exists by checking for Ember.TEMPLATES['user/edit'] in the console. It’s possible that wherever you placed the template file in your app doesn’t match what your build tool expects and so the template could not be found.


#6

Thank you, I’ll take a look at it again :slight_smile: