Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Rails 3.2 render :json differences #15

awt opened this Issue · 1 comment

2 participants


It appears that rails 3.2 implements render :json a bit differently than rails 3.1 did for arrays -- it generates an object with a property named after the resource instead of just returning a json array.

So instead of [], you get {resources: []}

This breaks findAll for me. I fixed it by overriding findAll in my controllers. I'm not sure what a good overall fix would be, however, as there is currently no setting with the plural form of the resource name, which is what is required to access the array inside the returned json object.

Here's my crappy fix for my categories controller:

  findAll: function(){
    var self = this;

    return this._resourceRequest({type: 'GET'})
    .done(function(json) {

Thanks for bringing this up. Although Rails has flip-flopped on the default, it is possible to control whether the root element is included by adding the following to an initializer:

# Disable root element in JSON by default.
ActiveSupport.on_load(:active_record) do
  self.include_root_in_json = false

For a working example, see my ember_rest_example.

At this point, I'm still considering whether to support both formats in ember-rest. The logic you're using could easily be generalized in the base controller.

@dgeb dgeb closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.