Rails ActiveResource with custom REST collection schema?
<p>I am trying to set up some Rails model working on top of the active_resource gem (ActiveResource) </p>

<pre><code>module Core
    class RestResource &lt; ActiveResource::Base
        self.format = :json
    end
end

module Core
    module API
        class BaseModel &lt; ::Core::RestResource
        self.site = ENV['API_URI']
        self.headers['Api-Token'] = ENV['API_TOKEN']
        end
    end
end

module Core
    module API
        class MyModel &lt; ::Core::API::BaseModel
        end
    end
end
</code></pre>

<p>And I am trying to run the rails console as following</p>

<pre><code>2.3.1 :001 &gt; MyModel = Core::API::MyModel
 =&gt; Core::API::MyModel 
2.3.1 :002 &gt; MyModel.all
ArgumentError: expected an attributes Hash, got ["data", [{"first_name"=&gt;"walter", "last_name"=&gt;"white", "timestamp"=&gt;1478515925}]]
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/base.rb:1377:in `load'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/base.rb:1124:in `initialize'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/base.rb:1051:in `new'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/base.rb:1051:in `instantiate_record'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/base.rb:1047:in `block in instantiate_collection'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/collection.rb:68:in `block in collect!'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/collection.rb:8:in `each'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/collection.rb:8:in `each'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/collection.rb:68:in `collect!'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/base.rb:1047:in `instantiate_collection'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/base.rb:1016:in `find_every'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/base.rb:923:in `find'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/bundler/gems/activeresource-f4bec7f8f389/lib/active_resource/base.rb:949:in `all'
    from (irb):2
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /Users/nakwa/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `&lt;top (required)&gt;'
    from bin/rails:4:in `require'
    from bin/rails:4:in `&lt;main&gt;'
2.3.1 :003 &gt; 
</code></pre>

<p>On my rails console (rails instance powering the API) I can see </p>

<pre><code>Started GET "/v1/my_model.json" for ::1 at 2016-11-08 16:42:11 +0100
Processing by V1::MyModelController#index as JSON
  MyModel Load (0.2ms)  SELECT "my_model".* FROM "my_model"
[active_model_serializers] Rendered V1::MyModelSerializer with MyModelSerializer::Adapter::Attributes (2.2ms)
Completed 200 OK in 13ms (Views: 2.8ms | ActiveRecord: 1.8ms)
</code></pre>

<p>My understanding is that Rails activeresource is expecting the JSON API to return something like : </p>

<pre><code>[
  {"first_name": "walter", "last_name": "white"}, 
  {"first_name": "chuck", "last_name": "norris"}
]
</code></pre>

<p>When my collections looks like this: </p>

<pre><code>{
  "data": [
    {"first_name": "walter", "last_name": "white"}, 
    {"first_name": "chuck", "last_name": "norris"}
  ],
  "collection": {
    "total_entries": 2
  }
}
</code></pre>

<p>I am now look for a nice way of customising the ActiveResource Collection parser, probably something like backbone.js is doing (<a href="http://backbonejs.org/#Collection-parse" rel="nofollow noreferrer">http://backbonejs.org/#Collection-parse</a>) but somehow I can't find out an obvious answer to that question. </p>

<p>Any idea? Thanks!</p>