The tutorial shows two new config options that target JSON, especially the to_json method: ActiveRecord::Base.include_root_in_json and ActiveSupport.use_standard_json_time_format
Here are the respective changesets and some more information on these changes:
Changeset 9202: Tweak ActiveRecord::Base#to_json to include a root value in the returned hash: {post: {title: ...}}
This is almost a nice change. I mean almost because it might help you when feeding your Ext JS forms via a Ext.data.JsonReader, but it'll break your Ext JS grids, when using the Ext.data.JsonReader.
Currently, you do something like the following in your javascript code:
orders_ds = new Ext.data.Store({
reader: new Ext.data.JsonReader({root: 'orders', id: 'id' }, orders_items),
proxy: new Ext.data.HttpProxy({url: orders_path_json})
});
and the following in your controller action:
render :json => { :orders => @orders }
which returns a JSON data in the following format
{"orders": [{"id": 1, ...}, {"id": 1, ...}]}
Well, after you turn on the ActiveRecord::Base.include_root_in_json option, it'll return:
{"orders": [{"order": {"id": 1, ...}}, {"order": {"id": 2, ...}}]}
which cannot be understood by your Ext.data.JsonReader by default.
It would be smarter if the include_root_in_json would differ between a single active record object and a collection of active record objects.
Therefore, if you use render :json => @orders or @orders.to_json, it would return the data in an array without a root for each object, but with the plural name of the model class name as root for the array. Just as I showed in the first JSON data example.
Well, maybe I'll write a patch for Rails for that.
Changeset 9203: Add config.active_support.use_standard_json_time_format setting so that Times and Dates export to ISO 8601 dates.
If you turn on this config option, it will probably also break your Ext JS grids. But you can easily fix that...
Right now you probably have this code in your record layout part when dealing with dates:
{ name: 'release_date', type: 'date', dateFormat: 'Y/m/d' }
Well, your JsonReader assumes that the date format is Y/m/d. But after you turned the use_standard_json_time_format option on, it will return the date in the default JSON date format.
It means you have to change the date format to the following:
{ name: 'release_date', type: 'date', dateFormat: 'Y-m-d' }
Well, these Rails changes are all JSON related changes that come in the soon to be releases Rails 2.1, but which won't really make your life easier with Ext JS. Sorry to disappoint you on that. But Rails is certainly going into the right direction.

