View Full Version : Uncaught ReferenceError: id is not defined When .save() with REST Model

Jeff Blake
17 Jan 2011, 1:12 PM
My backend is rails and here is my code:

Ext.regModel("User", {
fields: [
{name: "id", mapping: "user[id]"},
{name: "email", mapping: 'user[email]', type: "string"},
{name: "password", mapping: 'user[password]', type: "string"}
proxy: {
type: 'rest',
url : '/users',
format: 'ext_json',
appendId: false,
reader: {
successProperty: 'success',
idProperty: 'data.user[id]',
type: 'json',
root: function(data) {
if (data.data) {
if (data.data instanceof Array) {
return data.data;
} else {
return [data.data];
writer: {
type: 'json',
root: 'user'



and the Save action:

var user = Ext.ModelMgr.create({email: this.getValues().Email, password: this.getValues().Password}, 'User');


JSON Code received:


It's like it can't find the id in the returned JSON. I've tried specifying ID properties, manually passing the id with @user.to_ext_json(:id => x)

It's got to be some weird way the backend and frontend are communicating with each other. In order to read the JSON into rails I have to do this weird thing:
@user = User.new(params[:user][0])
Because sencha sends a single array'ed structure.

Jeff Blake
18 Jan 2011, 3:54 PM
It's a JSON issue. The to_ext_json function was not giving me usable stuff, so I ended up sending regular rails json to sencha and then wrapping it in an array ([response]) so sencha could read it.