1
votes

Is there a way to pass a params object to a linTo or action helper?

I have an object and it needs compound keys. I am using Ember Model and had to modify the adapter. In the Router that gets the initial object i pass a params object with the necessary keys. My problem is trying to do the same thing when using either a linkTo or action with a transitionToRoute. Neither hit the router again as far as I can tell.

Im coming back to this questions. Im still not sure the proper way to handle this.

App.Router.map(function () {
  this.resource("clients", { path: 'clients' }, function () {
    this.resource("client", { path: ':client_id' }, function () {
      this.resource("claims", function () {
        this.resource('claim', { path: ':claim_id/:claim_sub' }, function () {
          this.resource('lines', { path: 'lines' }, function () {
            this.resource('line', { path: ':line_id' }, function () {
              this.resource('flags', function () {
                this.resource('flag', { path: ':flag_id' });
              });
            });
            this.route('claim_lines');
          });
         });
       });
     });
  });
  this.route("errors", { path: '/errors/:error_id' });
});

When i link to anything under the claim, where the compound slugs are, i get those set to undefined.

UPDATE

The serialize was just what i needed.

App.ClaimRoute = Nucleus.Route.extend({
  model: function (params) {
    params.client_id = this.modelFor('client').get('client_id');
    return App.Claim.find('claim', params);
  },

  serialize: function (model) {
    return { claim_id: model.get('cla_seq'), claim_sub: model.get('cla_sub') };
  }
});
1
can you show code please...intuitivepixel

1 Answers

4
votes

I think a code example will be most helpful, but to try to answer your question, yes you can pass an object to linkTo with something like the following:

{{#linkTo routename params}}Text for Link{{/linkTo}}

Then for the route code matching the route name, you can take params as a parameter when you define the serialize function and use them to build the URL to match the routing segments defined in your router:

  serialize: function(params) {
    // params.property1 and params.property2
    return { segment_1: params.property1, segment_2: params.property2 };
  }