Search code examples
ember.jsrouteshttp-status-code-404ember-cli

ember/ember-cli - impossible url fetched while routing


I am new to Ember, but I got a successful "app" with it, then i'm trying to "port" it to ember-cli.

I have a quite empty main page, and a link to the about page: main and about routes are defined.

However I got a 404 "/mains" not found when accessing /… why the hell is he adding an extra "s"?

I've uploaded the project:

https://github.com/Leryan/testember/

https://raw.githubusercontent.com/Leryan/testember/master/2015-03-21-202815_1920x1080_scrot.png

You'll see a picture with the problem: when accessing the website root, ember try to fetch "/mains" …

Thanks


Solution

  • Ember is looking for the all the records of the type 'main' by calling this url.

    This is because in the router "main.js" you are using this.store.find method, which pluralizes the model type to retrieve all the records for this model ("/mains"):

    var MainRoute = Ember.Route.extend({
        model: function() {
            return this.store.find('main');
        }
    });
    

    But it looks like you want to use fixtures instead?

    Therefore you have to use the FixtureAdapter for the desired route and define the fixtures for the model. To use the FixtureAdapter you must rename your existing adapter "all.js" to "application.js" or "main.js" depending where you want to use it.

    And furthermore you have to use reopenClass to assign any fixtures in your model "main.js":

    Main.reopenClass({
      FIXTURES : [
        { id: 1, name: "blah" },
        { id: 2, name: "blah2" }
      ]
    });
    

    Here is the ember gudie for the fixture adapter: http://emberjs.com/guides/models/the-fixture-adapter/