vendredi 23 octobre 2015

Dynamic segments in ember js

I'm new to ember js. I was trying to use dynamic segments in my ember project and it give me an error.I tried localhost/4200/profile/john in my browser to get the info of "john".I think it is complaining about api end point in server.js.. Please help me to find what i have done wrong.

error display in console:

GET localhost:4500/api/users/john 404 (Not Found)

These are my files;

router.js

Router.map(function() {

   this.resource('profile', { path: '/profile/:username' });
});

model/user.js

import DS from 'ember-data';

export default DS.Model.extend({


    docType:DS.attr('string'),
    firstName:DS.attr('string'),


    userName:DS.attr('string'),
    password:DS.attr('string'),

    lastName:DS.attr('string'),
    mobileNo:DS.attr('string'),
    landNo:DS.attr('string'),
    address:DS.attr(
        {
        no:'string',
        street:'string',
        city:'string'
    }
    ),

    nicNo:DS.attr('string'),
    created_at:DS.attr('date'),
    updated_at:DS.attr('date')

});

route/profile.js

import Ember from 'ember';

export default Ember.Route.extend({

    model: function(params, transition) {
        return this.get('store').find('user', params.username);
    }

});

server.js

app.get('/api/users', function(req,res) {
    UserModel.find({},function(err,docs) {
        if(err) {
            res.send({error:err});
        }
        else {
            res.send({user:docs});
        }
    });
});

template/profile.hbs

<h2>Welcome user</h2>

{{#each item in model}}
{{item.userName}}
{{/each}}




Aucun commentaire:

Enregistrer un commentaire