开发者

ExtJs4 json data.store and Rails

I'm trying to create a simple CRUD application using ExtJs4 and Ruby On Rails. I'm trying to implement resftul datata store with JSON.

I have problem with updating a record. The request is being sent to the server side and database is being updated but in the data store I still have record marked as "dirty". And when I'm trying to update an another record I have two request sent (one for previous record and another for the next record).

Also I have problems with creating a new record. A record is being created on the server side, but in my data store it's still marked as unsaved (dirty) so during next update / create action that record sent to the server once again and in the outcome I have duplicated records in my db.

The question is - how to build a valid data store and corresponding model to开发者_C百科 work with restful json from Rails?

Sources of my application you can find on my github account: https://github.com/lucassus/extjs4-account-manager

the store: https://github.com/lucassus/extjs4-account-manager/blob/master/public/javascripts/app/store/Users.js and the model: https://github.com/lucassus/extjs4-account-manager/blob/master/public/javascripts/app/model/User.js


The reason for this is that the ExtJS JsonReader is expecting the 'users' root to be an array. This means that when it just gets a single user object back from your create and update actions, it cannot parse it properly, so does not correctly update the models to mark the received changes, and consequently remove the dirty flag.

To make this work, you can change the format lines in your rails actions as per this:

format.json { render :json => { :success => true, :users => [@user] } }

(Note the square brackets about the single user object)

This will then properly update the dirty flags.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜