Ruby on Rails and ExtJS 4 Data Model

Posted on 02 Jun 2011

I’ve been playing around a lot with rails 3 recently, and since I’ve spent many years working with the ExtJS platform from Sencha, and spend most of my working day with it, I thought it was about time I looked at combining the two. With the release of ExtJS 4, there are some extremely cool data and client side model tools.

One of the lovely things I find about the rails system is its attitude to JSON serialisation configuration. When you have a complex domain object graph, based on deep, and bidirectional relationships, context aware JSON serialisation can be a bit of a pain. (Looking at you, and your message converters Spring Framework). However, there is a little bit of an oddity with the default way rails scaffolding suggests REST states vs the way ExtJS expects them. In short, when returning a single object, Rails very sensibly encourages you to JSON it as an object. However, if you’re trying to simplify the Ext model side, you need an array.

Essentially, the problem is neatly expressed (as is usually the case) at stack overflow:

Oh, and my solution is there too. Basically, it is just “wrap objects in an array for ExtJS”.

StackOverflow Flair

profile for Simon Elliston Ball at Stack Overflow, Q&A for professional and enthusiast programmers