1. #1
    Sencha User
    Join Date
    Dec 2010
    Posts
    18
    Vote Rating
    1
    Jeff Blake is on a distinguished road

      0  

    Default Uncaught ReferenceError: id is not defined When .save() with REST Model

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


    My backend is rails and here is my code:
    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:
    Code:
    var user = Ext.ModelMgr.create({email: this.getValues().Email, password: this.getValues().Password}, 'User');
    
    	
    
    		        user.save();
    JSON Code received:

    Code:
    {"data":{"user[hashed_password]":"cde242c8118b05d7279200ac5e95b1e137e6fb25","user[updated_at]":"2011-01-17T21:03:55Z","user[registered]":null,"user[last_login]":null,"user[created_at]":"2011-01-17T21:03:55Z","user[email]":"hjghffg@dfklddf.com","user[id]":74},"success":true}
    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:
    Code:
    @user = User.new(params[:user][0])
    Because sencha sends a single array'ed structure.

  2. #2
    Sencha User
    Join Date
    Dec 2010
    Posts
    18
    Vote Rating
    1
    Jeff Blake is on a distinguished road

      0  

    Default


    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.

Similar Threads

  1. Replies: 1
    Last Post: 23 Feb 2010, 12:15 AM
  2. Replies: 1
    Last Post: 4 Dec 2008, 5:12 PM
  3. Save the column model changes
    By Shaguar in forum Ext 2.x: Help & Discussion
    Replies: 13
    Last Post: 17 Nov 2008, 12:13 PM