I purchased play by play of Ember.js at peepcode.com and followed as the video offered.
So, I set the Model and Serializer and Controllers up in Rails.
When I typed URL like this.
http://localhost:3000/actors/wycats
the JSON response rendered as I expected. (It's probably Ember-data's expecting JSON form..right?)
{
"actor": {
"id": 1,
"blog": "http://www.yehudakatz.com",
"company": "Tilde, Inc.",
"email": "[email protected]",
"gravatar_id": "428167a3ec72235ba971162924492609",
"location": "San Francisco",
"login": "wycats",
"name": "Yehuda Katz",
"actor_type": "User"
}
}
So I set up the Store and Actor Model in ember.js
GithubScore.Store = DS.Store.extend({
revision: 11,
adapter: "DS.RESTAdapter"
});
GithubScore.Actor = DS.Model.extend({
login: DS.attr('string'),
name: DS.attr('string'),
gravatarId: DS.attr('string'),
location: DS.attr('string'),
blog: DS.attr('string')
});
And I launched my Ember App, No error occurred.
but when I tried to get a model using console ( I already had a model saved in Rails DB with ID of 1 )
GithubScore.Actor.find(1)
It returns a Class, No error occurred, but When I try to get an attribute of it. it returns only null, although the model's status 'isLoaded'
GithubScore.Actor.find(1).get('isLoaded')
=> true
GithubScore.Actor.find(1).get('blog')
=> null
and I found that when I call GithubScore.Actor.find(1).get('isLoaded') repeatly at first time it returns only false, but when I try to get an attribute 'isLoaded' is changed to true immediately.
GithubScore.Actor.find(1).get('isLoaded')
=> false (for many times)
GithubScore.Actor.find(1).get('blog')
=> null
GithubScore.Actor.find(1).get('isLoaded')
=> true (immediately changed)
and when I try .toJSON() method to model as the video did. It throws an error.
GithubScore.Actor.find(1).toJSON()
=> TypeError: Object <GithubScore.Actor:ember272:1> has no method 'toJSON'
One thing I curious about is that, though GithubScore.Store object is extended from DS.Store.
It doesn't have find(type, id) method which DS.store already has.
I can't find what the problems are. Would you give me some help?
Thank you for reading!