Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Rails 3.2 render :json differences #15

Closed
awt opened this Issue · 1 comment

2 participants

@awt

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) {
      self.clearAll();
      self.loadAll(json.categories);
    }); 
  }
@dgeb
Owner

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
end

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.