Kris
Kris

Reputation: 89

Ember Dynamic Segment Unavailable in Route

I have the following router setup in Ember where I am trying to capture a dynamic search term and pass it to the router for querying ember-data.

Router

this.resource('resources', function() {
  this.resource('resource', { path: '/:resource_id' }, function() {});
  this.resource('search', { path: '/search/:search_term' }, function() {});
  this.route('new');
});

Route

export default Ember.Route.extend({
  model: function(params) {
    return this.store.findQuery('resource', {
      sTerm: params.search_term,
      limit: 15,
      offset: 0      
    });
  }
});

Unfortunately, search_term in not available in the route to pass into the query, I am unsure what is causing this not to work. If someone can point me in the right direction I would sure appreciate it. Thanks.

Update as requested

Logging this.constructor produces the following:

lrs-ui@route:search/index:

I have built this with ember-cli and the route is in search/index so this makes sense. Should I just have the route at search maybe?

Answer

As @kingpin2k led to, the route was in search/index and it needed to be in search, then everything worked just fine.

Upvotes: 1

Views: 62

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

For historical sake, the index route doesn't pick up the params from the parent resource.

Changing the route from search/index to search fixed the issue.

Upvotes: 1

Related Questions