0
votes

In my application I want to read the parameters user is entering and then I want to use that parameter. http://responsive.beta.postify.com/X I want to read that X value. But first how do I ensure that the router expects a parameter?

My router is like this

Cards.Router.map(function ()
{
    this.resource('cards', {path: '/'}, function ()
    {
      // additional child routes
      this.resource('selectImage');
      this.resource('message');
      this.resource('recipient');
      this.resource('orderStatus');
      this.resource('thankyou');
      this.resource('accountInfo');
      this.resource('recentOrders');
      this.resource('howTo');
      this.resource('faq');

   });

});

I want that parameter whenever the app loads. That is going to be my clientID which I would be using to fetch data from server depending upon the client.

Any thoughts on it?

When I do something like this

 Cards.Router.map(function ()
{
    this.resource('cards', {path: ':clientID'}, function ()
    {
      // additional child routes
      this.resource('selectImage');
      this.resource('message');
      this.resource('recipient');
      this.resource('orderStatus');
      this.resource('thankyou');
      this.resource('accountInfo');
      this.resource('recentOrders');
      this.resource('howTo');
      this.resource('faq');

   });

});

and in my browser if I put like this http://responsive.beta.postify.com/#/26 then its working but if I do like http://responsive.beta.postify.com/26 then it is not working.

1

1 Answers

0
votes

To answer your question directly, to use a parameter in a route you would do something like this:

this.resource('cards', { path: '/:user_id' });

Then in your route

App.CardsRoute = Ember.Route.extend({
  model: function(params) {
    return this.store.find('post', params.user_id);
  }
});

This is how you can get a parameter in a certain route. Now as far as your application goes, using the code I posted above should get you that parameter as long as they access the root ('/') of your application on first load and have the user_id in the url.

I would suggest a different strategy maybe for getting the client_id and storing it for later user in your application. For example, in my application I have an Ember.Application.initializer({}) where I store the client_id. All depends on your server configuration and how your app is built, but I would definitely try and get the client_id a different way if you can!

Good luck.