borisrorsvort
borisrorsvort

Reputation: 906

How can I reuse/dry these routes in ember.js

I have these routes

  this.resource('politicians'); 

  this.resource('politician', { path: '/politicians/:politician_id', function () {
    // Non nested interface so non nested politician route.

    this.resource('questions', function () {
      this.resource('question', { path: ':question_id' });
    });
  });

  this.resource('questions', function () {
    this.resource('question', { path: ':question_id' });
  });

I'd like the question route to be rendered anywhere (using a modal) in the app without losing the current context, but still have a specific/unique url for each question, knowing that the question you got from the nested questions route and the non nested ones are the same.

this.resource('question', { path: ':question_id' });

The thing is that I don't want to make a custom outlet for that because then I won't have a url for each question.

Upvotes: 1

Views: 148

Answers (2)

Kingpin2k
Kingpin2k

Reputation: 47367

This sort of problem is best solved by using query-params and hooking up the modal based on params. If you don't want to do that you're really stuck with building questions into each route if you want it to be URL based.

Here's an example: http://emberjs.jsbin.com/ucanam/3566/edit

Upvotes: 1

Jake Haller-Roby
Jake Haller-Roby

Reputation: 6427

What you're looking for is Ember's {{render}} helper. Simply place a {{render 'question' questionModel}} inside the modal you wish to use.

You can learn about the render helper here

EDIT:

Here is a jsbin to show the basic idea of how to use a render tag in this way. This jsbin renders the same template in 2 different ways; Once tied to a route url and once by using the render helper.

jsbin here

Upvotes: 0

Related Questions