0
votes

I have an error when I try to get to URL "/posts" in my Ember app. I get a following error:

Uncaught Error: More context objects were passed than there are dynamic segments for the route: posts.index

Which is really puzzling, because there is no dynamic segment for index, my routes look like this:

Router.map(function() {
    this.route('posts', function() {
        this.route('new');
        this.route('show', {
            path: ':post_id'
        });
    });
});

part of the model (models/posts.js):

import DS from 'ember-data';
let Post = DS.Model.extend({
    title: DS.attr('string'),
    author: DS.attr('string'),
    content: DS.attr('string')
});

Post.reopenClass({
    FIXTURES: [
        {
            id: 1,
            title: "Random text",
            author: "Someone new",
            content: "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laudantium aspernatur quam qui commodi beatae placeat ducimus aliquam veritatis ullam sed! Sit assumenda aspernatur sunt harum accusamus, repellat labore! Repellendus, corporis!"
        }
    ]
});

export default Post;

My link which I use to get to /posts:

{{link-to 'Posts' 'posts'}}

Additional info: I am using ember-cli-cordova, so my environment.js contains "defaultLocationType: 'auto'" and I am also using fixtures, so I have a following adapter:

export default DS.FixtureAdapter.extend({
  host: config.apiUrl
});

Does anybody see any problem which would cause the error? Thank you in advance.

EDIT:

My post route (routes/posts/index.js) looks like this:

import Ember from 'ember';
export default Ember.Route.extend({
    model() {
        return this.store.findAll('post');
    }
});

When I comment out the line where I am getting data from the store, everything works fine, so it looks that the problem is somehow connected with the usage of fixtures maybe. I'll try to create the minimum example on ember jsBin, when I get home.

2

2 Answers

0
votes

It was a silly typo at the end - from the error message, I was focusing on the model and route of the index and forgot on a template itself. There is an "each" iterator in which I am creating a link to a detail of the post and there was a typo in a link-to, I had "{{#link-to "posts" post}}" instead of "{{#link-to "posts.show" post}}".

-1
votes

You should use {{link-to 'posts'}} instead of {{link-to 'Posts' 'posts'}}, because you don't have dymanic segments in posts route.